Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Using Tags correctly between NXOpen Python and wrapped Open C API

My previous post gets me so close to working with the NXOpen.UF module in Python, but I am missing something important.  I do not think I'm using tags correctly yet.  See if you can help me with this problem:

import NXOpen
import NXOpen.Annotations
import NXOpen.BlockStyler
import NXOpen.Drawings
import NXOpen.UF

theSession = NXOpen.Session.GetSession()
theUI = NXOpen.UI.GetUI()
theUFSession = NXOpen.UF.UFSession.GetUFSession
workPart = theSession.Parts.Work       
            
allNoteObjects = workPart.Notes
for thisNote in allNoteObjects:
    thisLayer = thisNote.Layer #to filter by layer            
    thisOrigin = thisNote.AnnotationOrigin #to filter by location
    thisTag = thisNote.Tag #the regular Python object tag
    np1 = NXOpen.UF.Tag(thisNote) #the UF session object tag
    thisType, thisSubtype = NXOpen.UF.Obj.AskTypeAndSubtype(np1)

 

(This is a snippet of code I've sanitized to just show the problem area.)

According to the documentation of the NXOpen Python wrapper here: https://docs.plm.automation.siemens.com/data_services/resources/nx/10/nx_api/en_US/custom/nxopen_pyt...

the value passed in AskTypeAndSubtype() as np1 is supposed to be a tag.

At first, I tried passing in thisTag as np1, but that gave an error saying it was an int, not an object:

error_170104c.png

 

The code as pictured above is getting the tag from the UF session, but I get this error message:

error_170104a.png

So, that is the right way to pass a tag, but now it looks like it really wanted an object, not a tag?  But I can't figure out how to get the object from the tag.  I've tried passing thisNote, but it complains that is the wrong type of object, like this:

error_170104b.png

 

Note, the NXOpen Python documentation online does not include anything about UF.Tag(), I lifted it from someone elses' example.

4 REPLIES

Re: Using Tags correctly between NXOpen Python and wrapped Open C API

The second error box is supposed to have this image:

error_170104d.png

Solution
Solution
Accepted by topic author robin_h_p
‎01-04-2017 05:35 PM

Re: Using Tags correctly between NXOpen Python and wrapped Open C API

You're not using the UFSession object, you're just referencing the class. Change:

 

thisType, thisSubtype = NXOpen.UF.Obj.AskTypeAndSubtype(np1)

 

to:

thisType, thisSubtype = theUFSession.Obj.AskTypeAndSubtype(thisNote.Tag)

Re: Using Tags correctly between NXOpen Python and wrapped Open C API

I changed it to this:

            thisType, thisSubtype = theUFSession.Obj.AskTypeAndSubtype(thisNote.Tag)

 

 

Then I get this error:

error_170104e.png

Re: Using Tags correctly between NXOpen Python and wrapped Open C API

BUT I just noticed that I needed this:

theUFSession = NXOpen.UF.UFSession.GetUFSession()

not this, which is what I have above:

 

theUFSession = NXOpen.UF.UFSession.GetUFSession

THAT seems to work when I include it with your fix.