Showing results for 
Search instead for 
Did you mean: 

Object vs Component Snap/OpenNX


I recorded a journal to see how to make a part in an assembly as a display part


Dim part1 As NXOpen.Part = CType(theSession.Parts.FindObject("Part_134_24"), NXOpen.Part)

Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
Dim status1 As NXOpen.PartCollection.SdpsStatus = Nothing
status1 = theSession.Parts.SetDisplay(part1, False, True, partLoadStatus1)


and I try to minic this with open dialog, so when I select the object, it will become display part.  The issue:  it cannot convert the object (body) to component. 


        ' Create a selection dialog
        Dim dialog = Selection.SelectObject("Please Select an Object")

        ' Display the dialog and get a result
        Dim result = dialog.Show()

        ' Display selected object 
        If result.Response <> Response.Cancel And result.Response <> Response.Back Then

            Dim partLoadStatus As NXOpen.PartLoadStatus = Nothing
            Dim component As Snap.NX.Component = CType(result.Object, Snap.NX.Component)
            theSession.Parts.SetWorkComponent(component, False, True, partLoadStatus)

        End If

My thought: I may have 2 choices: either somehow refer the object to component or make the selection to be component instead of object - but as the starter, I look into Snap Referebce Guide and I could not find any details example on Selection.



Re: Object vs Component Snap/OpenNX

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

If you have a reference to an object (NXObject), you can use the .IsOccurrence property to determine if it is owned by a component or a part. If it is owned by a component, you can use the .Prototype and .OwningPart property to get the part.


dim myObj as NXObject = some object

dim myObjPart as part

if myObj.IsOccurrence then
    'object belongs to a component
    'find owning component and use it to find part
    myObjPart = myObj.OwningComponent.Prototype.OwningPart
    'object does not belong to a component
    myObjPart = myObj.OwningPart
end if

'code to set myObjPart as the display part


Re: Object vs Component Snap/OpenNX


Thanks - I just read another post (also from you) "Difference between Part, BasePart and Component" and I have much better understand now.