So I use a method that I have seen many places before to cycle through all children for the displayed part. I am outputting certain properties from these children and saving to a CSV file.
Before I run my journal file, I apply a variant condition to only allow certain children. The problem is that when I run the journal, it shows ALL children, including those that were suppressed by the variant condition. I do not want this. I only want it to process those that obey the variant condition, which were already filtered.
Is there a property I can use to identify if the component is allowed by the variant?
My code:
'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
Module NXJournal
Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
Public myWriter as IO.StreamWriter
Public outputFile As String
Public outputString as String
Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display
Dim myDocs As String
myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
outputFile = IO.Path.Combine(myDocs, "Length_of_Line.csv")
outputString = ""
lw.Open
'open only for testing
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)
Dim sub_comp As Component
sub_comp = c.RootComponent
'*** end of code to process root component
'If sub_comp.Prototype.OwningPart.IsFullyLoaded Then
If sub_comp.IsSuppressed Then
'Do nothing if supressed
Else
'If sub_comp.Prototype.OwningPart.IsFullyLoaded then
'If c.IsOccurrence = true Then
lw.writeline(c.OwningPart.ComponentAssembly.ActiveArrangement.Name)
ReportComponentChildren(c.RootComponent, 0)
'End if
End If
else
'*** insert code to process piece part
end if
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: "& e.ToString)
End Try
lw.Close
Using myWriter As New IO.StreamWriter(outputFile, False)
myWriter.Writeline("File,Mass,Volume,Material,Material Number, Length of Line")
myWriter.write(outputString)
End Using
End Sub
'**********************************************************
Sub reportComponentChildren( ByVal comp As Component, _
ByVal indent As Integer)
For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
'*** end of code to process component or subassembly
'**try to get attributes of each component too
dim material as string = ""
dim mass as string = ""
dim volume as string = ""
dim material_number as string
try
material = child.getStringAttribute("P_MAT")
catch
material = ""
end try
try
mass = child.getStringAttribute("P_MASS")
catch
mass = ""
end try
try
volume = child.getStringAttribute("P_VOLUME")
catch
volume = ""
end try
material = Replace(material,",","")
Dim pos As Integer
Dim pos2 As Integer
pos = InStr(material, "998")
pos2 = InStr(material, "GMW15200")
if pos <> 0 or pos2 <> 0 then
if Len(material) >= 8 and pos <> 0 then
material_number = material.Substring(pos-1,7)
else
if Len(material) >= 8 and pos2 <> 0 then
material_number = material.Substring(pos2-1,8)
else
material_number = ""
end if
end if
outputString = outputString & child.DisplayName() & ","& mass & ","& volume & ","& material & ","& material_number
'open part as displayed part then grab length of line
Dim basePart11 As NXOpen.BasePart = Nothing
Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
Dim totalCurveLength As Double
totalCurveLength = 0
try
basePart11 = theSession.Parts.OpenBaseDisplay("@DB/"& child.DisplayName() , partLoadStatus1)
'shouldn't need to change actual displayed layer, since curve measurement is filtering by layer already
'Dim stateArray1(1) As NXOpen.Layer.StateInfo
'stateArray1(0) = New NXOpen.Layer.StateInfo(3, NXOpen.Layer.State.WorkLayer)
'stateArray1(1) = New NXOpen.Layer.StateInfo(1, NXOpen.Layer.State.Hidden)
'basePart11.Layers.ChangeStates(stateArray1, False)
totalCurveLength = 0
'iterate through the curve collection, add curve length to the running total
For Each aCurve As Curve In basePart11.Curves
If aCurve.Layer = 3 then
'If aCurve.Visible = true then
totalCurveLength += aCurve.GetLength
end if
Next
'report the component name, part file name, and total curve length
basePart11.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.CloseModified, Nothing)
catch
end try
lw.WriteLine("Lengh of Line = "& totalCurveLength.ToString)
lw.WriteLine("")
outputString = outputString & ","& totalCurveLength.ToString & Chrw(13)
end if
'**end getting attributes
if child.GetChildren.Length <> 0 then
'*** this is a subassembly, add code specific to subassemblies
'*** 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
'*** end of code to process root component
'If sub_comp.Prototype.OwningPart.IsFullyLoaded Then
If child.IsSuppressed Then
'Do nothing if supressed
Else
'If child.Prototype.OwningPart.IsFullyLoaded then
'If child.IsOccurrence = true Then
lw.writeline(child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
reportComponentChildren(child, indent + 1)
'End If
End If
Next
End Sub
'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************
End Module