A (naive!) question related to the type of "part" being active when running an NX open code. I am playing around with a few lines of code which deal with groups. The code must work if the active part is a .sim , a .fem or or a .afm. Tested the code with active part = .sim and so far so good
I am "lauching" the code to be executed after the followign check
Dim bCarryOn As Boolean = True
'Dim theBasePart As CAE.CaePart = theSession.Parts.BaseWork 'does not work if it's a .prt If TypeOf theBasePart Is CAE.SimPart Then theSimPart = CType(theBasePart, CAE.SimPart) ElseIf TypeOf theBasePart Is CAE.FemPart Then theFEMPart = CType(theBasePart, CAE.FEMPart) ElseIf TypeOf theBasePart Is CAE.AssyFemPart Then theAFEMPart = CType(theBasePart, CAE.AssyFemPart) Else bCarryOn = False End if
The snag is when I neend to convert the groups into an array
Dim workSimPart As CAE.SimPart = CType(theSession.Parts.BaseWork, CAE.SimPart) Dim aTheCAEGroups() As CAE.CaeGroup aTheCAEGroups = workSimPart.CaeGroups.ToArray()
Is there a "smart" way of checking what is the active part? if I was to run the code in a .fem then I think one would have something like
Dim workFemPart As CAE.FemPart = CType(theSession.Parts.BaseWork, CAE.FemPart) aTheCAEGroups = workFemPart.CaeGroups.ToArray()
The only think I can think of is a "Try loop" one for each type of part
Solved! Go to Solution.
Fempart, afmpart and simpart all inherit group methods from caepart. Do one check for a caepart type, then instantiate a caepart and do all of your group operations on the caepart.
I would typically do something like:
Dim caePart As CAE.CaePart = TryCast(theSession.Parts.BaseWork, CAE.CaePart) If caePart Is Nothing Then theNXMessageBox.Show("My App Name", NXMessageBox.DialogType.Error, "Work part is not a CAE part") Return End If Dim aTheCAEGroups() As CAE.CaeGroup = caePart.CaeGroups.ToArray()
Thaks for that JimB. That's the method I have used to get the a list group. The issue still appears later in the code when I need to access element and / or node based on a list (of label)
If one is is in an .fem part then if you try to "access" and element ID you would define something like
fEModel1 = CType(theFEMPart.FindObject("FEModel"), NXOpen.CAE.FEModel) For Each sitem As String In ListofFEElmLabel stemp = "Element[" & sitem &"]" Dim fEElement1 As CAE.FEElement = CType(fEModel1.Find(stemp), CAE.FEElement) theTaggedObjects(j)= fEElement1 Next sitem
The idea of using the Find() is to avoid setting an FEelementMap (or Nodemap). I put it in a Try loop. If the Find() does not work then the code just move on to the next one in the list. Maybe I have no choice put to set up the elementmap!
If one is in a sim or .afm then I think one need to figure out the femoccurence, along this line...
Dim fEModelOccurrence1 As CAE.FEModelOccurrence = CType(workSimPart.FindObject("FEModelOccurrence
For Each sitem As String In ListofFEElmLabel
stemp = "Element[" & sitem &"]"
Dim fEElement1 As CAE.FEElement = CType(fEModelOccurrence1.Find(stemp), CAE.FEElement)
(which implies looping though each of the occurences!)
I use a function such as this to get the nodeLabelMap when needed:
Function getNodeLabelMap(ByVal caePart As CAE.CaePart) As CAE.FENodeLabelMap getNodeLabelMap = Nothing If TypeOf caePart Is CAE.FemPart Then Dim femPart As CAE.FemPart = CType(caePart, CAE.FemPart) getNodeLabelMap = femPart.BaseFEModel.FenodeLabelMap End If If TypeOf caePart Is CAE.SimPart Then Dim simPart As CAE.SimPart = CType(caePart, CAE.SimPart) getNodeLabelMap = simPart.Simulation.Femodel.FenodeLabelMap End If End Function
And a similar function for elementLabelMap.