cancel
Showing results for 
Search instead for 
Did you mean: 

Find CAE Faces with python

Creator
Creator

Hello All,

 

this is my first post in this forum, I already found many helpful hints here, but now I'm stuck working on my problem:

 

I use python as programming language. I have a Block UI Styler dialog where I select some CAEFaces.

When i close this dialog, I would like to remember my selection, in order to automatically fill them into the dialog when it is opened again.

 

At the moment I write the tags of the selected CAEFaces in an external file, and when reopening the dialog, my plan was, to iterate all CAEFaces and compare the tags, in order to decide if they where previously selected.

 

Now my problem is, that I found no way to iterate all CAEFaces using python...

 

I found Collections for Bodies or Faces etc, but not for CAEFaces.

I found about the NXObjectManager (, but appearently it does not exist in the Python API.

At the moment I use:

 

objects = displaySimPart.Views.WorkView.AskVisibleObjects()
for myObject in objects:
        if type(myObject) == NXOpen.CAE.CAEFace:

but of course it only works if all desired CAEFaces are visible...

 

So my Question is:

- is there a way to iterate CAEFaces with the python API?

- or is there a smarter way to remember the selection from a dialog after closing it?

 

Thank you in advance!

Armin

 
12 REPLIES

Re: Find CAE Faces with python

Phenom
Phenom
I have no experience with CAE, so I can't help with iterating over the CAEFaces. But writing the tags to a file is NOT the way to go. The tags are not guaranteed to be the same between NX sessions or even after re-opening a part. The only way that will work is if you open the part and execute your code several times without closing the part.
Normally refinding objects is done by giving them meaningful names or adding attributes to them. There are more technical solutions (UDO), but names or attributes are the best place to start.
Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Find CAE Faces with python

Creator
Creator

I see your point, adding an attribute to the object should also work for me.

But i would still need to iterate over some collection to ask all the objects if the have the attribute that was added by myself?

 

 

Re: Find CAE Faces with python

Siemens Phenom Siemens Phenom
Siemens Phenom

Rule number 1 when dealing with NX object Tags is that they are not persistent across NX sessions, so if you expect the selection to be remembered across sessions, this approach will not work.

 

There are several approaches that you could use, including:

  • You could create a group of the selected faces, then restore the selection from that group. This is probably the simplest approach.
  • You could add a custom attribute to each selected face, then use one of the NXOpen.UF.UFObj.Cycle* methods to cycle through the objects in the part to find objects with the custom attribute.
  • You could create a UDO that links the selected faces together

Re: Find CAE Faces with python

Creator
Creator

Thanks to both of you!!

 

I will give the UDOs a try. Seems to be exactly what i need!

Re: Find CAE Faces with python

Phenom
Phenom

Re: Find CAE Faces with python

Phenom
Phenom

Have you looked at using handles?

 

Persistent Object References

 

 

Re: Find CAE Faces with python

Creator
Creator

I decided to start with the "attributes" approach:

 

In the dialog i select my CAEFaces and i set a user attribute.

Then i try to cycle all CAEFaces using:  

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

for polygon_body_tag in polygon_body_tags:
        (num_polygon_faces, polygon_face_tags) = theUfSession.Sf.BodyAskFaces(polygon_body_tag)
   
faceList=[]
for polygon_face_tag in polygon_face_tags:
        face=NXOpen.TaggedObjectManager.GetTaggedObject(polygon_face_tag)
            if face.HasUserAttribute("myAttribute", NXOpen.NXObjectAttributeType.Integer, -1):
                if face.GetIntegerUserAttribute("myAttribute", -1) == 1:
                    faceList.append(face)

But none of the cycled faces has the previously set attribute.

 

It seems that the objects I'm cycling are not the same as the objects from my selection (I compared Tags,  JournalIdentifiers, and Handles), even if I cycle them in the same journal where i call the selection dialog.

Nevertheless the type is always "NXOpen.CAE.CAEFace".

 

The second suggested way of cycling using this function:

 

    objectTag=theUFSession.Obj.CycleObjsInPart(workFemPart.Tag, NXOpen.UF.UFConstants.UF_caegeom_type, objectTag)

 

gives the same result. 

 

I have the feeling, that my problem stems from not understanding the hierarchy of the objects...

 

 

Re: Find CAE Faces with python

Phenom
Phenom
I can't comment on the first problem, but you are using CycleObjsInPart() wrong. The first parameter should be the tag of the part to search in.
Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Find CAE Faces with python

Creator
Creator

Ups, thanks for pointing that out, now I get the same result as with the AskAllPolygonBodies/BodyAskFaces cycle.