[COLOR=blue]Option[/color] [COLOR=blue]Strict[/color] [COLOR=blue]Off[/color]
[COLOR=blue]Imports[/color] System
[COLOR=blue]Imports[/color] NXOpen
[COLOR=blue]Imports[/color] NXOpen.UF
[COLOR=blue]Imports[/color] NXOpen.Assemblies
[COLOR=blue]Module[/color] NXJournal
[COLOR=blue]Public[/color] theSession [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()
[COLOR=blue]Public[/color] ufs [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession()
[COLOR=blue]Public[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] theSession.ListingWindow
[COLOR=blue]Sub[/color] Main()
[COLOR=blue]Dim[/color] workPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Work
[COLOR=blue]Dim[/color] dispPart [COLOR=blue]As[/color] Part [COLOR=blue]=[/color] theSession.Parts.Display
lw.Open()
[COLOR=blue]Try[/color]
[COLOR=blue]Dim[/color] c [COLOR=blue]As[/color] ComponentAssembly [COLOR=blue]=[/color] dispPart.ComponentAssembly
[COLOR=green]'to process the work part rather than the display part,[/color]
[COLOR=green]' comment the previous line and uncomment the following line[/color]
[COLOR=green]'Dim c As ComponentAssembly = workPart.ComponentAssembly[/color]
[COLOR=blue]If[/color] [COLOR=blue]Not[/color] IsNothing(c.RootComponent) [COLOR=blue]Then[/color]
[COLOR=green]'*** insert code to process 'root component' (assembly file)[/color]
lw.WriteLine("Assembly: " [COLOR=blue]&[/color] c.RootComponent.DisplayName)
lw.WriteLine(" [COLOR=blue]+[/color] Active Arrangement: " [COLOR=blue]&[/color] c.ActiveArrangement.Name)
[COLOR=green]'*** end of code to process root component[/color]
reportComponentChildren(c.RootComponent, 1)
[COLOR=blue]Else[/color]
[COLOR=green]'*** insert code to process piece part[/color]
lw.WriteLine("Part has no components")
End [COLOR=blue]If[/color]
[COLOR=blue]Catch[/color] e [COLOR=blue]As[/color] Exception
theSession.ListingWindow.WriteLine("Failed: " [COLOR=blue]&[/color] e.ToString)
End [COLOR=blue]Try[/color]
lw.Close()
End [COLOR=blue]Sub[/color]
[COLOR=green]'**********************************************************[/color]
[COLOR=blue]Sub[/color] reportComponentChildren(ByVal comp [COLOR=blue]As[/color] Component, [COLOR=blue]ByVal[/color] indent [COLOR=blue]As[/color] [COLOR=blue]Integer[/color])
[COLOR=blue]Dim[/color] numOccs(-1) [COLOR=blue]As[/color] Tag
[COLOR=blue]For[/color] [COLOR=blue]Each[/color] child [COLOR=blue]As[/color] Component [COLOR=blue]In[/color] comp.GetChildren()
[COLOR=green]'*** insert code to process component or subassembly[/color]
lw.WriteLine(New String(" ", indent * 2) & child.DisplayName & vbTab & child.Name)
[COLOR=blue]Try[/color]
ufs.Assem.AskOccsOfPart(comp.Prototype.OwningPart.Tag, child.Prototype.OwningPart.Tag, numOccs)
lw.WriteLine(New String(" ", indent * 2) & "Quantity: " [COLOR=blue]&[/color] numOccs.GetLength(0))
[COLOR=blue]Catch[/color] ex [COLOR=blue]As[/color] System.NullReferenceException
lw.WriteLine(New String(" ", indent * 2) & "*** Component quantity information unavailable (component not loaded)")
[COLOR=blue]Catch[/color] ex [COLOR=blue]As[/color] ApplicationException
End [COLOR=blue]Try[/color]
[COLOR=green]'*** end of code to process component or subassembly[/color]
[COLOR=blue]If[/color] child.GetChildren.Length <> 0 [COLOR=blue]Then[/color]
[COLOR=green]'*** this is a subassembly, add code specific to subassemblies[/color]
lw.WriteLine(New String(" ", indent * 2) & _
"* subassembly with " [COLOR=blue]&[/color] _
child.GetChildren.Length [COLOR=blue]&[/color] " components")
lw.WriteLine(New String(" ", indent * 2) & _
" [COLOR=blue]+[/color] Active Arrangement: " [COLOR=blue]&[/color] _
child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
[COLOR=green]'*** end of code to process subassembly[/color]
[COLOR=blue]Else[/color]
[COLOR=green]'this component has no children (it is a leaf node)[/color]
[COLOR=green]'add any code specific to bottom level components[/color]
End [COLOR=blue]If[/color]
lw.WriteLine("")
reportComponentChildren(child, indent [COLOR=blue]+[/color] 1)
[COLOR=blue]Next[/color]
End [COLOR=blue]Sub[/color]
[COLOR=green]'**********************************************************[/color]
[COLOR=blue]Public[/color] [COLOR=blue]Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As[/color] [COLOR=blue]String[/color]) [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]
[COLOR=blue]Return[/color] Session.LibraryUnloadOption.Immediately
End [COLOR=blue]Function[/color]
[COLOR=green]'**********************************************************[/color]
End [COLOR=blue]Module[/color]