making an .afm the work part rather than the display part?

To all,

In a previous tread (http://www.nxjournaling.com/content/correct-syntax-find-element-afm) a solution kindly provided was to switch between the .sim (part) and the .afm (part) (associated to the .sim) in order to establish the element map required. This works fine. I am now looking to see if only making the .afm part the work part rather than the display part will speed up the program. I have recorded the steps required (see below) but I am a bit stuck in replacing the .FindObject(). I cannot find the appropriate command in the doc. Can anyone point me in the right direction?

Thanks in anticipation

Regards

JXB

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workSimPart As CAE.SimPart = CType(theSession.Parts.BaseWork, CAE.SimPart)

Dim displaySimPart As CAE.SimPart = CType(theSession.Parts.BaseDisplay, CAE.SimPart)

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Make Work Part")

Dim component1 As Assemblies.Component = CType(workSimPart.ComponentAssembly.RootComponent.FindObject("COMPONENT my_afem_test 1"), Assemblies.Component)

Dim partLoadStatus1 As PartLoadStatus
theSession.Parts.SetWorkComponent(component1, partLoadStatus1)

Dim workAssyFemPart As CAE.AssyFemPart = CType(theSession.Parts.BaseWork, CAE.AssyFemPart)

partLoadStatus1.Dispose()

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Make Work Part")

Dim nullAssemblies_Component As Assemblies.Component = Nothing

Dim partLoadStatus2 As PartLoadStatus
theSession.Parts.SetWorkComponent(nullAssemblies_Component, partLoadStatus2)

workSimPart = CType(theSession.Parts.BaseWork, CAE.SimPart)
partLoadStatus2.Dispose()

End Sub
End Module

With the previous code, we can immediately find the .fem or .afm part associated to a .sim file.

Two strategies immediately come to mind:

1) Loop through the components of the .sim file, examine the component's .Prototype property (the part file), compare it to the known .fem or .afm part, if they match - we have the component that we need, make it the work part.

2) Using the known .fem (or .afm) part reference, use the .AskOccsOfPart method to get the corresponding component in the .sim file and make it the work part.

Method 2 is a bit more direct in that you will not have to iterate over the component assembly of the .sim part. However, .AskOccsOfPart is a UF function that returns tags, rather than directly returning a component. We'll then have to use the object manager to get the component of interest from the given tag.

Thanks for the suggestion. Will look into it. Thinking about the problem. Would it be possible to use the .Leaf property of the CAEpart to use in the .FindObject()?

theFEMCAEPart = theSimPart.FemPart
Dim searchstring as string = theFEMCAEPart.Leaf 'should return the name the attached .afm !

Dim component1 As Assemblies.Component = CType(workSimPart.ComponentAssembly.RootComponent.FindObject(searchstring)Assemblies.Component)

Just a thought!

Regards

JXB

Thanks
Regards

I do not know for sure if it will work or not; but it seems worth trying.
Please let us know how it goes!

by using .SetWork() it does the trick (Journal recording is a bit misleading/OTT)
'-------------------------
Dim theSession As Session = Session.GetSession()
' This assumes you are starting with a SIM part as the work part
Dim theSimPart As CAE.SimPart = theSession.Parts.BaseWork
Dim theFEMCAEPart As CAE.CaePart = theSimPart.FemPart

theSession.Parts.SetWork(theFEMCAEPart)
lw.writeline("Work part is now the FEMCAE part")

theSession.Parts.SetWork(theSimPart)
lw.writeline("Work part is now the SIM part")

Thanks
Regards

Well the following seems to work but I suspect it implies that there're is only 1 component (1 .afm) attached to the .sim file.
Will post more when figure out
'--------------------------------------
Dim theSimPart As CAE.SimPart = theSession.Parts.BaseWork
Dim theFEMCAEPart As CAE.CaePart = theSimPart.FemPart
Dim strAFMName as String = theFEMCAEPart.Leaf
strAFMName = "COMPONENT "& strAFMName &" 1"

Dim component1 As Assemblies.Component = CType(theSimPart.ComponentAssembly.RootComponent.FindObject(strAFMName), Assemblies.Component)

Thanks
Regards