Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

How can I set back the work part after cycling through it´s components

Hello,

 

I would like to run a VB from a subassembly as my workpart (top-assy is only displayPart), cycling through some components as workparts, doing something there - e.g. getting attributes and expression values - and going back to the (start)-part - the subassembly, to do the rest.

 

Here is a (test) code which is working, but after cycling through the components, is makes the top-level-assembly to the work part, which is wrong in my case. I will habe the subassembly as the workpart at the end.

________________________________________________________________________________

' Walking throught an subassembly, making components to workpart,
' doing something and go back to the subassembly as workpart
'***************************************************************


Option Strict Off

Imports System
Imports System.IO
Imports System.Threading
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports NXOpenUI


Module NXJournal

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim theUI As UI = UI.GetUI()

Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("en-US")
Threading.Thread.CurrentThread.CurrentUICulture = New Globalization.CultureInfo("en-US")

Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

lw.Open

Try

Dim c As ComponentAssembly = workPart.ComponentAssembly

if not IsNothing(c.RootComponent) then

dim child() as component = c.RootComponent.getchildren()
for i as integer = 0 to ( child.length - 1 )
If Not child(i).IsSuppressed then

Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
theSession.Parts.SetWorkComponent(child(i), NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)
workPart = theSession.Parts.Work
partLoadStatus1.Dispose()

' do something here, e.g. read attributes and expressions

end if

next

'back to start-assy
Dim nullNXOpen_Assemblies_Component As NXOpen.Assemblies.Component = Nothing
Dim partLoadStatus2 As NXOpen.PartLoadStatus = Nothing
theSession.Parts.SetWorkComponent(nullNXOpen_Assemblies_Component, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus2)
workPart = theSession.Parts.Work
partLoadStatus2.Dispose()

else
'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

'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

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

'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------

End Function
'**********************************************************

End Module

________________________________________________________________________

 

First picture: the assy Structure, second - before running the code, third - after running the code:

assytest_4a_01.jpgassytest_4a_02.jpgassytest_4a_03.jpg

 

 

 

 

 

 

 

 

 

 

 

I changed a little bit in the area to go back to the start-part, I take the root component:

___________________________________________________________________

                'back to start-assy
                Dim partLoadStatus2 As NXOpen.PartLoadStatus = Nothing
                theSession.Parts.SetWorkComponent(c.RootComponent, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus2)
                workPart = theSession.Parts.Work
                partLoadStatus2.Dispose()

__________________________________________________________________

But this leaves the assy navigator in an undefined status:assytest_4b_01.jpgassytest_4b_02.jpg

 

 

 As you can see in the navigator, no part is the workpart, but in the title-bar, we can see the that it must be the subassembly.

 

What is wrong in my code? How can I save the current "start-Part" at the start of the program and to set back this part as the workPart at the end?

 

Best regards

 

Michael

 

 

 

 

 

 

 

 

Michael Eichelberg, CAD-Consultant, Dr. Wallner Engineering Nord GmbH
Production: NX10.0.3 MP16, NX11.0.1 MP4
Development: Batch and VB Testing: NX12
2 REPLIES
Solution
Solution
Accepted by topic author Michael_E
3 weeks ago

Betreff: How can I set back the work part after cycling through it´s components

[ Edited ]

If you do not modify the assembly structure you can just save the current work component before you cycle through your structure and reset it afterwards:

 

Dim origWorkComp As NXOpen.Assemblies.Component = theSession.Parts.WorkComponent

...

Dim partLoadStatus As NXOpen.PartLoadStatus
theSession.Parts.SetWorkComponent(origWorkComp, partLoadStatus)

Regards,

Jan

 

 

Jan Böttcher

Betreff: How can I set back the work part after cycling through it´s components

Hello Jan,

works fine! Thank you!

Michael
Michael Eichelberg, CAD-Consultant, Dr. Wallner Engineering Nord GmbH
Production: NX10.0.3 MP16, NX11.0.1 MP4
Development: Batch and VB Testing: NX12