cancel
Showing results for 
Search instead for 
Did you mean: 

Export Order of Assembly VBA

Creator
Creator

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)
            Next

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

 

Yoda

 

12 REPLIES

Re: Export Order of Assembly VBA

Legend
Legend

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

Re: Export Order of Assembly VBA

Creator
Creator
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.

TY

Re: Export Order of Assembly VBA

Phenom
Phenom

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

Genius
Genius

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

https://solutions.industrysoftware.automation.siemens.com/view.php?si=nx_api5467

Re: Export Order of Assembly VBA

Creator
Creator

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?

 

Thanks

 

Florante

Re: Export Order of Assembly VBA

Esteemed Contributor
Esteemed Contributor

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 (10.1.7.0) | TcVis 10.1
Development: VB.NET, Tcl/Tk    Testing: NX12.0

How to Get the Most from Your Signature in the Community

Re: Export Order of Assembly VBA

Creator
Creator

nx_error.PNG

 

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
        displayPart.ComponentAssembly.GetComponentOrders(theOrders)

        ' GetActiveOrder is new in NX10.0.3
        'Dim theCurrentOrder As Assemblies.Order =
        'displayPart.ComponentAssembly.GetActiveOrder()

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

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

        For Each anOrder As Assemblies.ComponentOrder In theOrders

            anOrder.Activate()
            theSession.UpdateManager.DoUpdate(markId1)

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

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

            theSession.UndoToMark(markId1, "")
        Next

        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)
        Next
    End Sub

    Sub Echo(ByVal output As String)
        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theSession.LogFile.WriteLine(output)
    End Sub

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

End Module

Thanks

 

Re: Export Order of Assembly VBA

Legend
Legend

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

Creator
Creator

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

 

nx_error3.PNG

 

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

 

Does the askchildrenorder works in NX10 properly?

 

Thanks