Showing results for 
Search instead for 
Do you mean 

How to fully load a part using NXOpen?

Hello, I was hoping somebody can alter a script to fully load a component in NX using NXOpen. I am using a script that I got from It processes all of the parts in an assembly. What I wanted to do was use it on large assemblies that were not loaded, so I can loop through the assembly and when I find the components in question that I want to open, open them and then move on until it finishes looping through the assembly. Can somebody help me put that together? I have the code I am using to process assemblies with right here:


'Journal to recursively walk through the assembly structure
' will run on assemblies or piece parts
' will step through all components of the displayed part
'NX 7.5, native
' February 24, 2012
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Module NXJournal
    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow
    Sub Main()
    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
        Dim c As ComponentAssembly = dispPart.ComponentAssembly
        'to process the work part rather than the display part,
        '  comment the previous line and uncomment the following line
        'Dim c As ComponentAssembly = workPart.ComponentAssembly
        if not IsNothing(c.RootComponent) then
            '*** insert code to process 'root component' (assembly file)
            lw.WriteLine("Assembly: " & c.RootComponent.DisplayName)
            lw.WriteLine(" + Active Arrangement: " & c.ActiveArrangement.Name)
            '*** end of code to process root component
            ReportComponentChildren(c.RootComponent, 0)
            '*** insert code to process piece part
            lw.WriteLine("Part has no components")
        end if
    Catch e As Exception
        theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
    End Try
    End Sub
    Sub reportComponentChildren( ByVal comp As Component, _
        ByVal indent As Integer)
        For Each child As Component In comp.GetChildren()
            '*** insert code to process component or subassembly
            lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
            '*** end of code to process component or subassembly
            if child.GetChildren.Length <> 0 then
                '*** this is a subassembly, add code specific to subassemblies
                lw.WriteLine(New String(" ", indent * 2) & _
                    "* subassembly with " & _
                    child.GetChildren.Length & " components")
                lw.WriteLine(New String(" ", indent * 2) & _
                    " + Active Arrangement: " & _
                '*** end of code to process subassembly
                'this component has no children (it is a leaf node)
                'add any code specific to bottom level components
            end if
            reportComponentChildren(child, indent + 1)
    End Sub
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function
End Module

Re: How to fully load a part using NXOpen?

The part object has an IsFullyLoaded Boolean property. You can test this to see if the part is fully loaded or not. If not, use the LoadFully() or LoadThisPartFully() methods on the part object to load it.

Re: How to fully load a part using NXOpen?

[ Edited ]

In addition to what JimB wrote, recording a journal is a great way to learn what API calls are necessary and useful. When I right click on a component in the assembly navigator, there is an option to "open fully"; when recording a journal of the action, I get the following code.



Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String) 

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Open Component Fully")

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Open Component")

Dim option1 As Boolean
option1 = theSession.Parts.LoadOptions.UsePartialLoading

theSession.Parts.LoadOptions.UsePartialLoading = False

Dim componentsToOpen1(0) As Assemblies.Component
Dim component1 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT 88175-sld 1"), Assemblies.Component)

componentsToOpen1(0) = component1
Dim option2 As Boolean
option2 = theSession.Parts.LoadOptions.UsePartialLoading

Dim openStatus1() As Assemblies.ComponentAssembly.OpenComponentStatus
Dim partLoadStatus1 As PartLoadStatus
partLoadStatus1 = workPart.ComponentAssembly.OpenComponents(Assemblies.ComponentAssembly.OpenOption.ComponentOnly, componentsToOpen1, openStatus1)

theSession.Parts.LoadOptions.UsePartialLoading = False

theSession.DeleteUndoMark(markId1, Nothing)

' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

Since you are iterating through the components, you would pass in your component of interest instead of using a "find object" call for "component1". The find object call is a result of recording a journal and should be replaced with your component.

Re: How to fully load a part using NXOpen?

Okay, well I think I am just unsure of the syntax I should use.


Should I use the method produced by the recording or the one that JimB recommended?


Also, is this the right syntax?:


Dim component1 As Assemblies.Component = CType _(workPart.ComponentAssembly.RootComponent.child, Assemblies.Component)



Re: How to fully load a part using NXOpen?

[ Edited ]

If you have a reference to a component, you can use the recorded code above (with a little modification to use your component of interest). The .LoadFully and .LoadThisPartFully methods mentioned by JimB must be used with a part object reference. You can get the part reference from a component reference with:


{part object} = {component}.Prototype.OwningPart

 Now that you have a part reference, you can use one of the .LoadFully methods to fully load the part.



"Also, is this the right syntax?"