Change between Sim to Fem or from or from Parent to child and back

I have been trying to figure out how to toggle between Sim and Fem parts and back, or from parent to child in an assembly.

I recorded a journal, but it uses file names as strings, it will not work for every file.

I need to make the Fem workpart and them make the Sim workpart again

Dim femPart1 As CAE.FemPart = CType(theSession.Parts.FindObject("test_Fem_File"), CAE.FemPart)
Dim workFemPart As CAE.FemPart = CType(theSession.Parts.BaseWork, CAE.FemPart)

this doesn't work, I can find the part using the string name, which sucks, but I still can't make it a work part.

I have no idea how to go about it,
the help file is no help at all.

Kiko

The following journal will switch from the sim part to the associated fem part. The code assumes that you are starting in the sim part; if a sim part is not active when the journal is run it will simply exit.

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

'Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

Dim mySimPart As CAE.SimPart
Try
mySimPart = CType(theSession.Parts.BaseWork, CAE.SimPart)
Catch ex As Exception
'not a sim part
Return
End Try

'switch to FEM part
MsgBox("switching to FEM part")
theSession.Parts.SetWork(mySimPart.FemPart)
'do work on the FEM part

'switch back to SIM part
MsgBox("switching back to SIM part")
theSession.Parts.SetWork(mySimPart)

lw.Close()

End Sub

End Module