Showing results for 
Search instead for 
Did you mean: 

Mapping Polygon Faces to CAD Faces within a NXOpen framework

Solution Partner Valued Contributor Solution Partner Valued Contributor
Solution Partner Valued Contributor

Quick Overview

This Tips & Trick shows how to map Polygon Faces (i.e., CAE faces) to CAD Faces. Given a CAD Face in the Modeling application, what is its corresponding CAE Face in the Advanced Simulation application ?

Core content

How to find the corresponding CAE Face for a given CAD Face ? Visually, it is obvious to make the match in most cases. For example, Figure 1 shows three (3) faces of a cube in the Modeling application (in a PART file) and their corresponding CAE faces in the FEM part. Equivalent faces share the same color.

However, when writing a NXOpen script, the user does not see the geometry. Therefore, making the match between CAD Faces and CAE Faces is not straightforward. How can we proceed ?

The case of bodies

Matching bodies in NXOpen is easier that matching faces. Indeed, there exist Open C functions that provide the polygon body that corresponds to a given solid / sheet CAD body, and vice versa. These functions are:

1. int UF_SF_modl_body_ask_body  (tag_t CAD_body,  tag_p_t cae_body )

Input: the CAD body.  It can be a solid or a sheet body.
Output: the CAE (polygon) body.

2. int UF_SF_body_ask_modl_body  (tag_t CAE Body, tag_p_t CAD Body )

Input:  the CAE (polygon) body. It can be a solid or a sheet body.
Ouput: the CAD body.  

The first function takes as input the tag of the CAD Body and returns the tag of the corresponding CAE Body. The second function takes as input the tag of the CAE Body and returns the tag of the corresponding CAD Body.

Unfortunately, there are no such functions for CAD and CAE Faces. A different and less explicit approach should be used.

Figure 1: Three (3) CAD Faces of a cube (TOP figure) and their corresponding Polygon Faces (BOTTOM figure).

The power of attributes

Attributes of NX Objects are automatically transferred from PART to FEM (the inverse is not true !). For example, if an attribute is set to a CAD Face, the equivalent CAE Face will inherit the same attribute. To set manually an attribute in NX, right-click on the desired NX Object, go to “Properties“ and select the “Attributes” tab.

Figure 2 shows the attributes dialog of Face # 3. We have created a string attribute with the title “HELLO” and the value “FACE”.

Figure 2: Setting an attribute for CAD Face # 3

Then we go to the FEM and open the attributes dialog for Polygon Face # 3. The polygon face inherits the attribute of its corresponding CAD face, as shown in Figure 3.

Mapping Polygon Faces to CAD Faces by using attributes.

After what has been discussed above, mapping between Polygon Faces and CAD Faces can be done using the following steps:

1. In the PART, loop over all CAD bodies using the Body Collection.

2. For each Body, get all the CAD Faces using the function GetFaces().

Figure 3: Attributes dialog for the Polygon Face # 3. The attributes are inherited from CAD Face # 3.

3. Loop over all the CAD Faces and for each, set a unique attribute using the function SetAttribute(). The attribute should be unique for each face. For example, set an attribute with title = “ID” and value = “FACE_1” for the first face and another attribute with title = “ID” and value = “FACE_2” for the second face.

4. Create a map that stores all the pairs (FACE, ID).

5. Go to the FEM.

6. Loop over all Polygon bodies using the function UF_SF_ask_all_polygon_bodies().

7. For each Polygon Body, get all the Polygon faces using the function UF_SF_body_ask_faces().

8. For each Polygon Face, read the attribute “ID” using the function GetUserAttribute().

9. Using the map created in step 4, find the corresponding CAD Face.

Maya Simulation: T +1.514.369.5706 | |

Re: Mapping Polygon Faces to CAD Faces within a NXOpen framework

Valued Contributor
Valued Contributor

Thank you for that  insight, it is most useful

After some research and coding I want to add a small remark.


Sometimes, it is needed to do the opposite - to be able to find the corresponding cad body/face from a selected cae body/face. This is first and foremost because UFModl functions (which are very useful for chechking the body/face properties) will only work on Body/Face objects but not on CAE.CAEBody/CAE.CAEFace. Sometimes, getting the needed geometric properties from UF.SF functions (which are available for CAE objects) can be both hard and messy. In that case it is much simpler to run the checks on the corresponding cad object and here the "power of attributes" does really come handy. Furthermore, since in that case, the entity of interest is known beforehand (either from user input or programmatically) there is no reason to create attributes for every cad  face in the model - it can rather be performed only on the faces of the corresponding cad body (which can be aquired from UFS.SF.BodyAskModlBody).

Below I add the code for the function that returns cad entity from the supplied cae one. It is written to work on solids and faces but surely can be extended to work on other geometrical entites (edges are my next goal). 

For function to work straightforward several Public (module level) declarations must be made:

Public ufs As UFSession = UFSession.GetUFSession()
Piblic theSession As Session = Session.GetSession
Public lw As ListingWindow = theSession.ListingWindow
Public workFemPart As CAE.FemPart = CType(theSession.Parts.BaseWork, CAE.FemPart)
Public idealizedPart As NXOpen.Part = workFemPart.IdealizedPart 

Function Itself:

Function GetModlEntity (ByVal caeObject As NXObject) As NXObject
	Dim modlObject AS NXObject 
	Dim modlObjectTag As Tag 
	Dim caeObjectType As String = caeObject.GetType().ToString()
	Select Case caeobjectType
		Case "NXOpen.CAE.CAEBody"
			UFS.SF.BodyAskModlBody (caeObject.Tag, modlObjectTag) 
			modlobject = NXOpen.Utilities.NXObjectManager.Get(modlObjectTag)
		Case "NXopen.CAE.CAEFace"
		Dim caeBodyTag, modlBodyTag, caeBodyFaceTags() As Tag 								'Defining the tag variables
		Dim numFaces As Integer 
		UFS.SF.FaceAskBody (caeObject.Tag, caeBodyTag)									'Getting the tag of a CAE body of the selected ca face (by Tag)
		UFS.SF.BodyAskModlBody (caeBodyTag, moal BodyTag) 								'Getting the model body of that CAE body (by Tag)
		Dim modlBody As Body NXOpen. Utilities. NXObjectManager.Get (modlBodyTag) 					              'Getting the model body object from its Tag 
		UFS.SF.BodyAskFaces (caeBodyTag, numfaces, caeBodyFaceTaga)							'Getting the array of faces of the CAE body (by Tag)
		For Each modlBodyFace As Face In modlBody.GetFaces ()								'For each of the model body faces
			'lw.WriteFullLine ( "Modl face tag is: "&modlBodyFace.Tag) 						'Printing its Tag (not mandatory)
			modlBodyFace.SetUserAttribute ("Tag", -1, modlBodyface.Tag.ToString, Update.Option.Now)                 'And setting user attribute of title (type) "Tag" and value of the Tag
		workFemPart.SetAssociatedCadAsWork (idealizedpart) 								'Refreshing the model (changing workpart to _i and back again)
		workFemPart.SetFemAsWork()											'The defined attributes are now updated in the cae geometry
		Dim femFaceAttr As String = caeObject. GetStringUserAttribute ("tag", -1) 					'Getting the nos present attribute of the selected cae face
		For Each modlBodyFace As Face In modlBody.GetFaces()								'For each face the faces of the model body
			If modlBodyFace.Tag.ToString = femFaceAttr								'If its Tag (which is equal to its attribute) is equal to the
				modlObject = modlBodyFace									'attribute of the selected cae face - return that model face
				lw.WriteFullIine ("Found model body tag is: "&modlBodyFace.Tag) 
			End If 
			modlBodyFace.DeleteUserAttributes(NXObject.AttributeType.String, Update.Option.Now)		        'Removing the attribute from the model face		
		workFemPart.SetAssociatedCadAsWork(idealizedPart) 								'Refreshing the model (changing workpart to _i and back again)
		workFemFart.SetFemAsWork											'The removed attributes are now deleted from the cae geometry
		Dim topoType As Integer 
		UFS.Modl.AskFaceTopology (modlObject.Tag, topoType) 								'Checking that UFModl functions are
		lw.writeFullline ("Model face topology type indicator is: "&topotype)						'Working for the returning object
	End Select
	Return modlObject
End Function