Check TC release status assembly loop

Hello all,

To get the release status of a part i use the following test code (see first one below) and this works fine.

I tried now to loop through an assembly to get the status and then the value is empty. It´s just the Loop code from the tutorial with PDMPart.GetReleaseStatus. Could someone give me a hint what i am doing wrong?

Thank you very much in advance

Code Test

Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
MsgBox (workPart.PdmPart.GetReleaseStatus())

End Sub

Code Assembly

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)
lw.WriteLine(" + Status: " & c.OwningPart.PdmPart.GetReleaseStatus())
'*** end of code to process root component

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)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly
lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())
'*** 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(New String(" ", indent * 2) & _
"* subassembly with " & _
child.GetChildren.Length & " components")
lw.WriteLine(New String(" ", indent * 2) & _
" + Active Arrangement: " & _
child.OwningPart.ComponentAssembly.ActiveArrangement.Name)

lw.WriteLine(New String(" ", indent * 2) & " + Status: " & child.OwningPart.PdmPart.GetReleaseStatus())
'*** 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
lw.WriteLine(New String(" ", indent * 2) & " + Status: " & child.OwningPart.PdmPart.GetReleaseStatus())
end if
reportComponentChildren(child, indent + 1)
Next
End Sub

The expression "child.OwningPart" will return the the assembly that owns the component; not the component part, which is, what I expect you are after. Try using the following instead:

child.Prototype.OwningPart.PdmPart.GetReleaseStatus()

The prototype of a component is the component part. You might be able to only use the Prototype and eliminate the OwningPart in the above line. However, I prefer to keep the "OwningPart" as it seems to implicitly cast the prototype to a part object. Otherwise, you may have to cast the prototype explicitly. This is not a bad thing, but more a coding preference.

Also, an empty status means that the item rev has no status.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.UF

Module Module199

Dim theSession As Session = Session.GetSession()

Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

If IsNothing(theSession.Parts.BaseDisplay) Then
'need at least 1 open part
Return
End If

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
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)

lw.WriteLine(New String(" ", indent * 2) & " " & comp.DisplayName)
lw.WriteLine(New String(" ", indent * 2) & " + Status: " & comp.Prototype.OwningPart.PDMPart.GetReleaseStatus())

For Each child As Component In comp.GetChildren()
reportComponentChildren(child, indent + 1)
Next
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Thank you a lot. It works perfect. Also for the explanation: "The prototype of a component is the component part". Will help me a lot in the future.

Best regards