Cancel
Showing results for 
Search instead for 
Did you mean: 

Find a named polygon face with NXopen python

Siemens Creator Siemens Creator
Siemens Creator

Hi,

 

is there some example how to find a caeface in the sim file.

So I have a face called diskcface_1 and i want to create a region with this face.

 

How do i find the face?

    objects1[0] = NXOpen.CAE.SetObject()
    component1 = workSimPart.ComponentAssembly.RootComponent.FindObject("COMPONENT disk_assyfem1 1")
    component2 = component1.FindObject("COMPONENT disk2_fem1 1")
    cAEFace1=component2.FindObject("PROTO#CAE_Body(26)|CAE_Face(1950)")

So I can find the assembly component (fem file) by name but for bodies and faces FindObject is only working with the journal identifier.

Would be NXOpen.UF.Obj.CycleByNameAndType the right class?

How do I use this? 

8 REPLIES

Re: Find a named polygon face with NXopen python

Siemens Phenom Siemens Phenom
Siemens Phenom

You can use NXOpen.UF.UFSf.AskAllPolygonBodies() to get all of the bodies. For each  body, use NXOpen.UF.UFSf.BodyAskFaces() to get the faces.

 

Or you can do as you suggest and use NXOpen.UF.UFObj.CycleByNameAndType(), looking for objects with type UFConstants.UF_caegeom_type. You would then need to use NXOpen.UF.UFObj.ask_type_and_subtype() to verify that the subtype is UFConstants.UF_caegeom_face_subtype

Re: Find a named polygon face with NXopen python

Siemens Legend Siemens Legend
Siemens Legend

I have a Python subroutine that will return all faces with a certain Name Root in the Facename.
It is implemented as you suggest - maybe it helps in your script.

 

def getCaeFacesByNameRoot(part, nameRoot):

theUFSession=NXOpen.UF.UFSession.GetUFSession()

faceList=[]

objectTag=0
objectTag=theUFSession.Obj.CycleObjsInPart(part.Tag, NXOpen.UF.UFConstants.UF_caegeom_type, objectTag)
while objectTag!=0:
(objType, objSubType) = theUFSession.Obj.AskTypeAndSubtype(objectTag)
if objSubType == NXOpen.UF.UFConstants.UF_caegeom_face_subtype:
face=NXOpen.TaggedObjectManager.GetTaggedObject(objectTag)
if nameRoot.upper() in face.Name.upper():
faceList.append(face)
objectTag = theUFSession.Obj.CycleObjsInPart(part.Tag, NXOpen.UF.UFConstants.UF_caegeom_type, objectTag)
faceList.sort(key=getKey)
return faceList

 Regards

Boris

Re: Find a named polygon face with NXopen python

Siemens Creator Siemens Creator
Siemens Creator

Hi thank you both of you.

 

But how do i get the 'part' or body for your function.

If i ask for all polygonbodies  like JimB suggested:

    allbodies=theUfSession.Sf.AskAllPolygonBodies()
    numpoly=allbodies[0]#Number of Polygon Bodies
    theUI = NXOpen.UI.GetUI()
    theNxMessageBox = theUI.NXMessageBox
    theNxMessageBox.Show("Number of Polygonbodies", NXOpen.NXMessageBox.DialogType.Information,str(numpoly))

 i get 0 number of Polygon bodies.(i have 3 caebodies in this sim file)

I know that is my cae body.

cAEbody1 = component2.FindObject("PROTO#CAE_Body(26)")

I would like to have a function: findfaceofbody(bodyname,facename) [which is an obvious function and should be built in NXopen]

Re: Find a named polygon face with NXopen python

Siemens Phenom Siemens Phenom
Siemens Phenom

Try this

 

import NXOpen
import NXOpen.UF

theSession = NXOpen.Session.GetSession()
theLw = theSession.ListingWindow
theUfSession = NXOpen.UF.UFSession.GetUFSession()

def main(*args): 

    # Add your application code here
    theLw.Open()

    (num_polygon_bodies, polygon_body_tags) = theUfSession.Sf.AskAllPolygonBodies()

    theLw.WriteLine("Number of bodies: " + str(num_polygon_bodies))

    for polygon_body_tag in polygon_body_tags:

        (num_polygon_faces, polygon_face_tags) = theUfSession.Sf.BodyAskFaces(polygon_body_tag)

        theLw.WriteLine("BodyTag: " + str(polygon_body_tag) + "     Number of faces: " + str(num_polygon_faces))
        
# Main program.

if __name__ == "__main__":
    main()

Re: Find a named polygon face with NXopen python

Siemens Creator Siemens Creator
Siemens Creator

Hi I still have problems.

I can now Identify a face in the fem part (not in the SIM part)

But this host pointer is not the right one I want to create a region in the sim part and do a contact boundary condition.

"NXOpen.NXExeption: Selected objects are not in the same file as the Targetset"

So if i have the host pointer in the fem part how do I get this converted to the sim part.

This simple source code creates a region in a sim file with two simple cubes.

import math
import NXOpen
import NXOpen.Assemblies
import NXOpen.CAE
import NXOpen.UF
def main() : 

    theSession  = NXOpen.Session.GetSession()
    theLw = theSession.ListingWindow
    theUfSession = NXOpen.UF.UFSession.GetUFSession()
    workSimPart = theSession.Parts.BaseWork
    displaySimPart = theSession.Parts.BaseDisplay
    markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")
    
    simSimulation1 = workSimPart.FindObject("Simulation")
    caeRegionBuilder1 = simSimulation1.CreateCaeRegionBuilder("Region", NXOpen.CAE.CaeRegion.Null)
    
    theSession.SetUndoMarkName(markId1, "Region Dialog")
   
    simPart1 = workSimPart
    simSimulation2 = simPart1.Simulation
    
    markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, None)
    
    setManager1 = caeRegionBuilder1.TargetSetManager
    
    objects1 = [None] * 1 
    objects1[0] = NXOpen.CAE.SetObject()
    component1 = workSimPart.ComponentAssembly.RootComponent.FindObject("COMPONENT assyfem1 1")
    component2 = component1.FindObject("COMPONENT Body1_fem1 1")
    partLoadStatus1 = theSession.Parts.SetWorkComponent(component2)
    theLw.Open()

    (num_polygon_bodies, polygon_body_tags) = theUfSession.Sf.AskAllPolygonBodies()

    theLw.WriteLine("Number of bodies: " + str(num_polygon_bodies))

    for polygon_body_tag in polygon_body_tags:

        (num_polygon_faces, polygon_face_tags) = theUfSession.Sf.BodyAskFaces(polygon_body_tag)

        theLw.WriteLine("BodyTag: " + str(polygon_body_tag) + "     Number of faces: " + str(num_polygon_faces))
        
    workFemPart = theSession.Parts.BaseWork
    facelist=getCaeFacesByNameRoot(workFemPart,"CONT")
    cAEFace1 = facelist[0] #<----_THIS DOES NOT WORK
    partLoadStatus1.Dispose()
    partLoadStatus2 = theSession.Parts.SetWorkComponent(NXOpen.Assemblies.Component.Null)
    #cAEFace1 = component2.FindObject("PROTO#CAE_Body(1)|CAE_Face(4)")#This does work!
    objects1[0].Obj = cAEFace1
    objects1[0].SubType = NXOpen.CAE.CaeSetObjectSubType.NotSet
    objects1[0].SubId = 0
    setManager1.SetTargetSetMembers(0, objects1)
    
    nXObject1 = caeRegionBuilder1.Commit()
    
    nErrs1 = theSession.UpdateManager.DoUpdate(markId4)
    
    
    theSession.SetUndoMarkName(markId1, "Region")
    
    caeRegionBuilder1.Destroy()
    

def getCaeFacesByNameRoot(part, nameRoot):
    
    theUFSession=NXOpen.UF.UFSession.GetUFSession()
    theSession  = NXOpen.Session.GetSession()
    theLwa = theSession.ListingWindow
    
    faceList=[]
    theLwa.Open()
    objectTag=0
    objectTag=theUFSession.Obj.CycleObjsInPart(part.Tag, NXOpen.UF.UFConstants.UF_caegeom_type, objectTag)
    while objectTag!=0:
        (objType, objSubType) = theUFSession.Obj.AskTypeAndSubtype(objectTag)
        if objSubType == NXOpen.UF.UFConstants.UF_caegeom_face_subtype:
            face=NXOpen.TaggedObjectManager.GetTaggedObject(objectTag)
            if nameRoot.upper() in face.Name.upper():
                faceList.append(face)
        objectTag = theUFSession.Obj.CycleObjsInPart(part.Tag, NXOpen.UF.UFConstants.UF_caegeom_type, objectTag)
    #faceList.sort(key=getKey)
    theLwa.WriteLine("Found CAE Contact face" + str(faceList) )
    return faceList        
if __name__ == '__main__':
    main()

 

So in the source code the bold text is where i get the face host pointer.

Is there a way to convert FEM face host pointer to Sim face host pointer?

Regards,

NXProblem.png

Re: Find a named polygon face with NXopen python

Siemens Creator Siemens Creator
Siemens Creator

Attached is a zip file with the simple two body assembly FEM where i want a contac face boundary condition between the two bodies.

And I want to create 2 regions ContBody1 and ContBody2 based on the named faces from the part files.

Re: Find a named polygon face with NXopen python

Siemens Phenom Siemens Phenom
Siemens Phenom
Option Strict Off
Imports System
Imports System.Collections.Generic

Imports NXOpen
Imports NXOpen.UF

Module Module2

    Dim theSession As Session = Session.GetSession()
    Dim theLw As ListingWindow = theSession.ListingWindow

    Dim theUI As UI = UI.GetUI
    Dim theNXMessageBox As NXMessageBox = theUI.NXMessageBox

    Dim theUfSession As UFSession = UFSession.GetUFSession


    '  Explicit Activation
    '      This entry point is used to activate the application explicitly
    Sub Main()

        ' TODO: Add your application code here 
        Dim basePart As BasePart = theSession.Parts.BaseWork

        Dim faceName As String = "CONTBODY1"

        Dim matchingFaces1 As New List(Of CAE.CAEFace)(getCaeFacesByName1(basePart, faceName))

        theLw.WriteLine(vbNewLine)
        theLw.WriteLine(String.Format("getCaeFacesByName1 found {0} faces named {1}", matchingFaces1.Count, faceName))
        theLw.WriteLine(vbNewLine)

        Dim matchingFaces2 As New List(Of CAE.CAEFace)(getCaeFacesByName2(basePart, faceName))

        theLw.WriteLine(vbNewLine)
        theLw.WriteLine(String.Format("getCaeFacesByName2 found {0} faces named {1}", matchingFaces2.Count, faceName))

    End Sub

    Function getCaeFacesByName1(ByVal basePart As BasePart, ByVal name As String) As List(Of CAE.CAEFace)

        getCaeFacesByName1 = New List(Of CAE.CAEFace)
        theLw.Open()

        Dim objectTag As Tag
        theUfSession.Obj.CycleByNameAndType(basePart.Tag, name, NXOpen.UF.UFConstants.UF_caegeom_type, True, objectTag)

        Do While objectTag <> NXOpen.Tag.Null
            Dim nxobject As NXObject = NXOpen.Utilities.NXObjectManager.Get(objectTag)
            Dim objType As Integer = 0
            Dim objSubType As Integer = 0

            theUfSession.Obj.AskTypeAndSubtype(objectTag, objType, objSubType)

            If objSubType = NXOpen.UF.UFConstants.UF_caegeom_face_subtype Then
                Dim face As CAE.CAEFace = CType(nxobject, CAE.CAEFace)
                theLw.WriteLine(face.Name)
                getCaeFacesByName1.Add(face)
            End If

            theUfSession.Obj.CycleByNameAndType(basePart.Tag, name, NXOpen.UF.UFConstants.UF_caegeom_type, True, objectTag)
        Loop

    End Function

    Function getCaeFacesByName2(ByVal basePart As BasePart, ByVal name As String) As List(Of CAE.CAEFace)

        getCaeFacesByName2 = New List(Of CAE.CAEFace)
        theLw.Open()

        Dim objectTag As Tag
        theUfSession.Obj.CycleObjsInPart(basePart.Tag, NXOpen.UF.UFConstants.UF_caegeom_type, objectTag)

        Do While objectTag <> NXOpen.Tag.Null
            Dim nxobject As NXObject = NXOpen.Utilities.NXObjectManager.Get(objectTag)
            Dim objType As Integer = 0
            Dim objSubType As Integer = 0

            theUfSession.Obj.AskTypeAndSubtype(objectTag, objType, objSubType)

            If objSubType = NXOpen.UF.UFConstants.UF_caegeom_face_subtype Then
                Dim face As CAE.CAEFace = CType(nxobject, CAE.CAEFace)
                theLw.WriteLine(face.Name)
                If face.Name = name Then getCaeFacesByName2.Add(face)
            End If

            theUfSession.Obj.CycleObjsInPart(basePart.Tag, NXOpen.UF.UFConstants.UF_caegeom_type, objectTag)
        Loop

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        '----Other unload options-------
        'Unloads the image when the NX session terminates
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module

Re: Find a named polygon face with NXopen python

Honored Contributor
Honored Contributor

The FEM file is a component of the SIM file. If you have a reference to the FEM component and the prototype polygon face in the FEM file, you can find the corresponding occurrence face in the SIM file with the .FindOccurrence method. It would look something like:

 

SimFace = FemComponent.FindOccurrence(protoFemFace)