' 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
'NXJournaling.com February 24, 2012
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpen.features
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
lw.Open
Try
'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)
'ovb top assembly
lw.writeline("top asm " & workpart.leaf)
theSession.Information.DisplayPartHistory(workPart)
'ovb
'*** end of code to process root component
lw.writeline("")
ReportComponentChildren(c.RootComponent, 0)
else
'*** 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
lw.Close
End Sub
'**********************************************************
Sub reportComponentChildren( ByVal comp As Component, _
ByVal indent As Integer)
dim namefeature as string = " "
dim test as string = " "
dim strMyString as string = " "
dim Bodystring as string = " "
dim i as integer = 0
dim j as integer = 0
For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
'lw.WriteLine(New String("1", indent * 2) & child.DisplayName())
'lw.WriteLine(child.DisplayName())
'Dim part1 As Part = CType(theSession.Parts.FindObject(child.DisplayName()), Part)
Dim part1 as Part = child.Prototype.OwningPart
'lw.writeline("part1: "& part1.leaf)
'theSession.Information.DisplayPartHistory(part1)
'lw.writeline("comp: "& comp.displayname)
dim pls1 as PartLoadStatus
'*** make work part
thesession.parts.setworkcomponent(child, pls1)
dim farray() as feature = thesession.parts.work.features.getfeatures()
'*** test of work part is a part starting with Hex Par Dis indicating library element to be skipped for processing
test= left(part1.leaf.tostring,3)
select case test
case "Hex"
lw.writeline("bout")
case "Par"
lw.writeline("cilindrische pen")
case "Dis"
lw.writeline("onderleg ring")
case Else
lw.writeline("Part met volgende features: "& part1.leaf)
'lw.writeline(" features!!! from " & child.displayname)
for each myfeature as feature in farray
namefeature=myfeature.getfeaturename
'lw.writeline(" each lus namefeature :" & namefeature)
Bodystring = " "
Bodystring = Mid(Namefeature,1, 4)
if Bodystring = "Body" then
i= i+1
'lw.WriteLine("In lus each: " & i)
end if
if Bodystring = "soli" then
j= j+1
'lw.WriteLine("In lus each: " & j)
end if
'lw.writeline(" " & Namefeature)
strMyString = myFeature.Timestamp.ToString
next
lw.writeline(" ")
lw.WriteLine(" " & strMyString & " " & NameFeature)
lw.writeline(" ")
theSession.Information.DisplayPartHistory(part1)
lw.writeline(" ")
if i > 0 then
lw.WriteLine("Number of bodies: " & i & " bodies bodies bodies!!!!!!!!" )
end if
if j > 0 then
lw.WriteLine("Number of solids: " & j & " solids solids solids!!!!!!!!" )
end if
i=0
j=0
lw.WriteLine(".Timestamp: " & strMyString & " " & NameFeature & " " & part1.leaf )
lw.writeline(" ")
end select
'*** 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("* subassembly with " & _
child.GetChildren.Length & " components")
lw.WriteLine(" + Active Arrangement: " & _
child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
'*** end of code to process subassembly
else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components
end if
lw.writeline("")
reportComponentChildren(child, indent + 1)
Next
End Sub
'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************
End Module