I am trying to create an Assy with 2 Levels as shown below using nxjournaling.
(2 levels are just examples, there could be 4 or 5 levels, then the way to setworkpart as suggested by NX it will be complicated)
With Lv2, when I execute the setworkpart code using the method below, there is an error message "Attempted to set invalid part to be the work part"
Please help me correct the above error
For each iChild as component in Lv1.Getchildren()
'The condition to recognize iChild is Lv2
Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
theSession.Parts.SetWorkComponent(iChild , NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)
partLoadStatus1.Dispose()
next
(In NX 11 there is no such error)
I tried to record the degree using journaling to setworkpart for Lv2 and the code has the structure as below.
Imports System
Imports NXOpen
Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Make Work Part")
Dim component1 As NXOpen.Assemblies.Component = CType(displayPart.ComponentAssembly.RootComponent.FindObject("COMPONENT @DB/Level 1 Part No/AA 1"), NXOpen.Assemblies.Component)
Dim component2 As NXOpen.Assemblies.Component = CType(component1.FindObject("COMPONENT @DB/Level 2 Part No/AA 1"), NXOpen.Assemblies.Component)
Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
theSession.Parts.SetWorkComponent(component2, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)
partLoadStatus1.Dispose()
theSession.SetUndoMarkName(markId1, "Make Work Part")
End Sub
End Module
re: set work part
When a sub-assembly is added to the top level assembly, the top level assembly gets its own "copy" of each component. The component specified in the SetWorkComponent function must belong to the current displayed part. It is impossible to tell from your code snippet, but I suspect that the component copy that belongs to the subassembly is being passed in where the copy that belongs to the displayed part should be used.