Showing results for 
Search instead for 
Do you mean 

Export Order of Assembly VBA

[ Edited ]

Hi everyone.


I am currently doing a journal to export assembly to excel and it is working except for the order in the navigation window. I want the exported data to follow the same order in the navigation window.



Here is part of my code



            For Each child_component As Component In Component_.GetChildren()
'some more code here
                getcomponent_info(child_component, indent + 2)

The GetChildren method gives the order of the output but it is not the same with the navigation window.


Can anybody direct me  how to order my parts in the assembly as in the navigation window?


Thank you very much





Re: Export Order of Assembly VBA

Search for 'report displayed assembly components in various orders' on soluton center.

Re: Export Order of Assembly VBA

HI Technisites,

I tried to search as you suggested but to no avail. on the other hand, it looks like order.AskchildrenOrder does not work properly on NX9. I may have to revisit this when we upgrade to at least nx 10.


Re: Export Order of Assembly VBA

Where did you search? I went to the Solution Centre and searched using the suggested string and found exactly 1 API program dealing with your issue.

Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Export Order of Assembly VBA

nx_api5467 'report displayed assembly components in various orders'  VB language

Re: Export Order of Assembly VBA

My apology , I think I search the wrong place. 


The solution here seems to work on NX10. We are still on NX9. I have read somewhere that AskChildrenOrder does not work properly on NX9. Can you confirm?





Re: Export Order of Assembly VBA

For NX 9 you can try GetChildrenOrder, which is deprecated in NX 10.

Stefan Pendl, Systemmanager CAx, HAIDLMAIR GmbH
Production: NX10.0.3, VERICUT 8.0, FBM, MRL 3.1.4 | TcUA 10.1 MP7 Patch 0 ( | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX11.0 EAP, NX12.0 EAP

How to Get the Most from Your Signature in the Community

Re: Export Order of Assembly VBA



I modified the code posted above to use getchildrenOrder instead of askchildrenorder and got this error. 

I do not know what this error is. bellow is the code I use to test


Imports System
Imports NXOpen
Imports NXOpen.UF

Module NXJournal
    Dim theSession As Session = Session.GetSession()
    Dim theUFSession As UFSession = UFSession.GetUFSession()
    Dim workPart As Part = theSession.Parts.Work

    Public Sub Main(ByVal args As String())
        Dim displayPart As Part = theSession.Parts.Display

        Dim markId1 As NXOpen.Session.UndoMarkId = theSession.SetUndoMark(
            NXOpen.Session.MarkVisibility.Visible, "Reorder Components")

        Dim theOrders As Assemblies.ComponentOrder() = Nothing

        ' GetActiveOrder is new in NX10.0.3
        'Dim theCurrentOrder As Assemblies.Order =

        'Echo("The current Component Order is " & theCurrentOrder.Name)

        Echo(displayPart.Leaf & " has " & theOrders.Length & " ComponentOrder objects")

        For Each anOrder As Assemblies.ComponentOrder In theOrders


            Echo(anOrder.Name & ":")
            WalkAssemblyTree(displayPart.ComponentAssembly.RootComponent, anOrder, "")

            theUFSession.Ui.DisplayMessage(anOrder.Name, 1)

            theSession.UndoToMark(markId1, "")

        theSession.DeleteUndoMarksUpToMark(markId1, "", False)

    End Sub

    Sub WalkAssemblyTree(ByVal theComponent As NXOpen.Assemblies.Component,
                        ByVal theOrder As NXOpen.Assemblies.ComponentOrder,
                        ByVal indent As String)

        Dim kids As Assemblies.Component() = theComponent.GetChildren()
        If kids.Length = 0 Then Return ' Not an assembly or sub-assembly

        indent = indent + "  "

        ' This does not always work - see PR 7487277 
        ' Testing in the Toycar assembly only Chronological returns any Children
        'kids = theOrder.AskChildrenOrder(theComponent.directowner)
        theOrder.getchildrenorder(theComponent.directowner, kids)

        For ii As Integer = 0 To kids.Length - 1
            Echo(indent & kids(ii).DisplayName)
            WalkAssemblyTree(kids(ii), theOrder, indent)
    End Sub

    Sub Echo(ByVal output As String)
    End Sub

    Public Function GetUnloadOption(ByVal arg As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function

End Module



Re: Export Order of Assembly VBA

I tested the code you posted and I did not get any error message.  But the 'kids' component array was empty for all component orders.  Seems to be a bug in NX9.  


It has been fixed in NX10.  The first parameter for GetChildrenOrder has to be a Component rather than a ComponentAssembly.

Re: Export Order of Assembly VBA

I think there is a substancial change in NX9  going to NX10. 




As commented in the code the AskChildrenOrder method does not even work properly for all order type. 


Does the askchildrenorder works in NX10 properly?