I have simple journal that walks through the assembly and attempts to fully load and un-blank any partially loaded components. My assembly is pre-loaded with partially loaded components that have not been un-blanked.
I'm noticing that with this particular assembly the .UnBlank() method will not work on a fully loaded component unless it has already been un-blanked. In other words unless I go in and un-blank the component manually. Which defeats the purpose of using the code in the first place. At least for my use case. I'm curious, does anyone know why this may be, or perhaps any other approaches I can take?
Imports System
Imports NXOpen
Imports NXOpen.Assemblies
Module NXJournal
Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Sub Main (ByVal args() As String)
Dim part1 As Part
part1 = theSession.Parts.Display
Dim c As Component = part1.ComponentAssembly.RootComponent
ShowAssemblyTree(c, "")
End Sub
Sub ShowAssemblyTree(ByVal c As Component, ByVal indent As String)
Dim children As Component() = c.GetChildren()
Dim newIndent As String
Dim childName as String
For Each child As Component In children
If indent.Length = 0 Then
newIndent = " "
Else
newIndent = indent & " "
End If
childName = child.DisplayName
Dim thePart As Part = child.Prototype.OwningPart
' fully load and un-blank all partially loaded components
Try
If thePart.IsFullyLoaded Then
echo(childName & " Is Loaded")
Else
' part is loaded partially,
child.Prototype.OwningPart.LoadThisPartFully()
child.UnBlank()
echo(childName & " Is partially Loaded")
End If
Catch ex As NullReferenceException
'component is not loaded
End Try
ShowAssemblyTree(child, newIndent)
Next
End Sub
Sub Echo(ByVal output As String)
theSession.ListingWindow.Open()
theSession.ListingWindow.WriteLine(output)
theSession.LogFile.WriteLine(output)
End Sub
End Module
re: unblank
If your assembly has one or more component that have been added multiple times (the quantity for a given component > 1), all component instances will show as fully loaded once the part has been fully loaded. Your code only attempts to unblank components that show as partially loaded; you need to unblank all the components.
For example, let's say we have a vehicle assembly that has 4 identical wheels. We model the wheel and add it as a component (x4). If the wheel is partially loaded and all 4 are blanked, your code finds the first wheel, fully loads it and unblanks it. Since the wheel is now fully loaded, your code sees the next wheel as fully loaded and does nothing more (repeat for the remaining wheels).
I suggest attempting to unblank every component whether it shows as fully loaded or not (something like below):
' fully load and un-blank all partially loaded components
Try
child.UnBlank()
If thePart.IsFullyLoaded Then
echo(childName & " Is Loaded")
Else
' part is loaded partially,
child.Prototype.OwningPart.LoadThisPartFully()
echo(childName & " Is partially Loaded")
End If
Catch ex As NullReferenceException
'component is not loaded
End Try