cancel
Showing results for 
Search instead for 
Did you mean: 

Dealing with .afm - How to?

Phenom
Phenom

To all,

I am struggling a bit with understanding the logic (i.e. the order one should define things ) to deal with .afm (FEM assembly). In other words the 'Inheritance Hierarchy' (It's more a reflection of my limited vb knowledge).

 

I am in a .sim file. So that's my base part (!)
  I tested it as follows:  If TypeOf theBasePart Is CAE.SimPart Then theLw.WriteLine("it's a SIM part!")

 

I want to access the .afm "attached" to the .sim file how does one go about it?


I am trying to modify the lines of codes I have (to access the element map) for a straightforward .fem but not no avail

 

Dim theSimPart As NXOpen.CAE.SimPart = theSession.Parts.BaseWork
Dim lngElemID As Long =1234
Dim femPart As NXOpen.CAE.BaseFemPart = theSimPart.FemPart
Dim elementMap As NXOpen.CAE.FEElementLabelMap = femPart.BaseFEModel.FeelementLabelMap
Dim theFEElm As NXOpen.CAE.FEElement = elementMap.GetElement(lngElemID)
Dim destinationElements1(0) As CAE.FEElement
  destinationElements1(0)=theFEElm

 

 

Any help would be appreciated.

 

Thanks

Regards

JXB

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)
16 REPLIES

Re: Dealing with .afm - How to?

Siemens Pioneer Siemens Pioneer
Siemens Pioneer

If you want to access elements in afm,

get the BaseFeModel,

cast to AssyFEMModel

get children FEModelOccurrences. For each, get the FeelementLabelMap.

 

The Feelementlabelmap in the assembly fem will contain only the elements created by that afm.

 

Here is an example

Dim objects1(0) As NXOpen.TaggedObject
Dim fEModelOccurrence1 As NXOpen.CAE.FEModelOccurrence = CType(workAssyFemPart.FindObject("FEModelOccurrence[2]"), NXOpen.CAE.FEModelOccurrence)

Dim fEElement1 As NXOpen.CAE.FEElement = CType(fEModelOccurrence1.Find("Element[317]"), NXOpen.CAE.FEElement)

objects1(0) = fEElement1
Dim added1 As Boolean
added1 = nodeElementInfoBuilder1.Element.Selection.Add(objects1)

Dim objects2(0) As NXOpen.TaggedObject
Dim assyFEModel1 As NXOpen.CAE.AssyFEModel = CType(workAssyFemPart.FindObject("AssyFEModel"), NXOpen.CAE.AssyFEModel)

Dim fEElement2 As NXOpen.CAE.FEElement = CType(assyFEModel1.Find("Element[1]"), NXOpen.CAE.FEElement)

 

 

 

MAYAHTT
www.mayahtt.com

Re: Dealing with .afm - How to?

Phenom
Phenom

Thaks for the input. I am still confused but managed to make very small progress. The few lines of (dummy) codes below "work" in that it's not crashing but where I am trying to print the name I get a blank ie nothing is printed. The .FullPath works. Any idea why?

 

Thanks

 

Rrgards

 

JXB

 

Dim theBasePart As BasePart = theSession.Parts.BaseWork
If TypeOf theBasePart Is CAE.AssyFemPart Then
  theAFModel  = CType(workAssyFemPart.BaseFEModel(), CAE.AssyFEModel)
  theLW.WriteLine("Full path is " & theBasePart.FullPath)
  theLW.WriteLine("Name AFM is " & theAFModel.Name)
Else
	theLw.WriteLine("it's NOT a Assy FEM part")
End If

Dim theFEModelOccur As CAE.FEModelOccurrence
For Each theFEModelOccur In theAFModel.GetChildren()
	theLW.WriteLine("Name FEM occurrence is " & theFEModelOccur.Name)
Next

 

 

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)

Re: Dealing with .afm - How to?

Honored Contributor
Honored Contributor

That means that the particular object does not have a custom name assigned to it. In other words, the value held by the name property is an empty string or a null value.

Re: Dealing with .afm - How to?

Siemens Pioneer Siemens Pioneer
Siemens Pioneer

Finding an FEModelOccurence by index is the same as looping through FEModelOccurences.

If I am not mistaken it is indexed from 1.

Try this: There is some labelling information which may be able to help.

 

Option Strict Off
Imports System
Imports NXOpen

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

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

Dim displayAssyFemPart As NXOpen.CAE.AssyFemPart = CType(theSession.Parts.BaseDisplay, NXOpen.CAE.AssyFemPart)

Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim caePart1 As NXOpen.CAE.CaePart = CType(workAssyFemPart, NXOpen.CAE.CaePart)
Dim assyFEModel1 As NXOpen.CAE.AssyFEModel = CType(workAssyFemPart.FindObject("AssyFEModel"), NXOpen.CAE.AssyFEModel)
Dim theFEModelOccur As CAE.FEModelOccurrence
Dim theLW as ListingWindow = theSession.ListingWindow()
For Each theFEModelOccur In assyFEModel1.GetChildren()
 theLW.WriteLine("Name FEM occurrence is: " & theFEModelOccur.Name)
 theLW.WriteLine(" Component Name:" &theFEModelOccur.GetCOmponent().Name)
 theLW.WriteLine(" Display Name:" &theFEModelOccur.GetCOmponent().DisplayName)
 Dim thefemoccattr AS CAE.FEModelOccAttribute = theFEModelOccur.GetAttributes()
     theLW.WriteLine("Attribute Name is: " & thefemoccattr.Name & "Label is:" & thefemoccattr.GetLabel)
Next


' ----------------------------------------------

End Sub
End Module

 

 

MAYAHTT
www.mayahtt.com

Re: Dealing with .afm - How to?

Phenom
Phenom

Thanks. I thought I was dealing with all the .fem making up the .afm by using the GetChildren()!

I decided to skip what I was trying to do (get the basic building blocks by understanding/playing with specific keywords) and tried something. And it seems to work !!! Happy to be shown a "smarter" way of coding such problem

 

Dim theBasePart As BasePart = theSession.Parts.BaseWork
Dim theAssyFEModel As CAE.AssyFEModel
Dim theFEModel As CAE.FEModel
Dim theAFEModel As CAE.AssyFEModel
Dim elementMap As CAE.FEElementLabelMap
	
If (theBasePart Is Nothing Or Not (TypeOf theBasePart Is CAE.BaseFemPart Or TypeOf theBasePart Is CAE.AssyFemPart)) Then
	theLw.WriteLine("Not a FEM or AFEM")
	Return
Else
 If TypeOf theBasePart Is CAE.FemPart Then
   thefemPart = CType(theBasePart, CAE.FemPart)
  theFEModel = CType(thefemPart.BaseFEModel(), CAE.FEModel)
  elementMap = theFEModel.FEElementLabelMap
 End if
 If TypeOf theBasePart Is CAE.AssyFemPart Then
		workAssyFemPart = CType(theBasePart, CAE.AssyFemPart)
 theAFEModel  = CType(workAssyFemPart.BaseFEModel(), CAE.AssyFEModel)
 elementMap = theAFEModel.FEElementLabelMap
 End if
End If

Dim lngElemID as Long = 1201 '<---user input

Dim theFEElm As CAE.FEElement = elementMap.GetElement(lngElemID)
Dim destinationElements1(0) As CAE.FEElement
	destinationElements1(0)=theFEElm

If (theFEElm Is Nothing) Then
	theLW.WriteLine ("Specified Element ID was not found - Line is skipped")
Else
	theLW.WriteLine ("Specified Element ID was found")	
End If

 

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)

Re: Dealing with .afm - How to?

Phenom
Phenom

Thanks. Another brick in the knowledge wall

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)

Re: Dealing with .afm - How to?

Phenom
Phenom

Keep trying to expand my vb programme. I am trying to get the FEM Part (either a.fem or a .afm) associated with the .sim. According to the doc:

'CAE.SimPart.FemPart' Returns the fem part associated with the sim part

so I tried the following but prgramme failed trying to get the Fempart associated. Any hints/pointers on which keyword is wrongly used?

 

Thanks

 

Regards

 

JXB

 

If TypeOf theBasePart Is CAE.SimPart Then

 theLw.WriteLine("it's a SIM part")
 'Returns the fem part associated with the sim part 
  Dim femPart As CAE.CAEPart = theSimPart.FemPart
'tried this one too but does not work
'Dim femPart As CAE.BaseFemPart = theSimPart.FemPart
  theLw.WriteLine("the part associated is " & femPart.Name)
Else
  theLw.WriteLine("it's NOT a SIM part")
End If	

 

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)

Re: Dealing with .afm - How to?

Honored Contributor
Honored Contributor

The code that you are currently using:

 

Dim femPart As CAE.CAEPart = theSimPart.FemPart

 

should work. I see that you are trying to report the .Name of the FEM part; for most NX objects, the name property is empty - it is there so the user can give the object a custom name. Instead of the .Name property, try reporting the .Leaf or .FullPath properties to see what the result is.

Re: Dealing with .afm - How to?

Phenom
Phenom

Thanks cowski1.

 

It should yet it doesn't.


If I try with a .fem associated with the .sim I get an error about 'Object reference not set to an instance of an object'


If I try with a .afm associated with the .sim using:

Dim femPart As CAE.CAEPart = theSimPart.AssyFemPart

I get an error an about 'AssyFEMPart' is not a member of 'NXOpen.CAE.SimPart'

The 2nd one is clearly telling me that it's the wrong way of "checking" the .afm associated with the .sim

Production: NX9.0.3.4, NX10.0.2.6
Development: VB.NET (amateur level !)