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:
The code as pictured above is getting the tag from the UF session, but I get this error message:
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:
Note, the NXOpen Python documentation online does not include anything about UF.Tag(), I lifted it from someone elses' example.
Solved! Go to Solution.
You're not using the UFSession object, you're just referencing the class. Change:
thisType, thisSubtype = NXOpen.UF.Obj.AskTypeAndSubtype(np1)
thisType, thisSubtype = theUFSession.Obj.AskTypeAndSubtype(thisNote.Tag)
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.