Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations Ron247 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using .AskChildrenOrder and Measure Bodies function

Status
Not open for further replies.

junfanbl

Marine/Ocean
Jun 10, 2015
90
Cab somebody assist me in altering the code below: I have spent some time trying to produce something that will work, but I can't seem to figure out.

I got this code off of the GTAC support website. It uses the .AskChildrenOrder function to output the components in the assembly navigator order inside a list window in the same order as the Assembly Navigator.

I am aware that it doesn't perform the way it should all of the time, but in this case it performs the way I need it too. What I want to do is use Measure Bodies function to measure the volume of each component in the assembly in the order that .AskChildrenOrder function processes each part. Can somebody help me? Thank you!

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)

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 & ":")
WalkAssembyTree(displayPart.ComponentAssembly.RootComponent, anOrder, "")

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

theSession.UndoToMark(markId1, "")
Next

theSession.DeleteUndoMarksUpToMark(markId1, "", False)

End Sub

Sub WalkAssembyTree(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 7421390
' Testing in the Toycar assembly only Chronological returns any Children
kids = theOrder.AskChildrenOrder(theComponent)

For ii As Integer = 0 To kids.Length - 1
Echo(indent & kids(ii).DisplayName)
WalkAssembyTree(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




































 
Status
Not open for further replies.

Part and Inventory Search

Sponsor