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

Get the sheet that a note resides on using python

I have not been able to figure out a way to get the sheet that a note object resides on using the NXOpen python API.  I've looked through the documentation, tried Google, tried adapting scripts that were posted to do the same thing in VB and Java, but nothing is working.  I have note objects.  I can get their layers, text, origins, but I also need to know their sheet.

 

I simply would like the string returned in the information listing that is labeled "Resides on drawing".  My usual trick of recording a journal and reverse-engineering it failed, because it just calls

theSession.Information.DisplayObjectsDetails(selectedObjects1)

 

and DisplayObjectsDetails does everything behind the scenes.  I'm about ready to have my python script read the listing window to brute-force getting the value, if that is even possible.

 

Do any of you have any clues for a python user?

8 REPLIES

Re: Get the sheet that a note resides on using python

FYI, the brute force method worked, but was difficult to implement due to a possible bug in the python API.  I sent the Listing Window to a file, but had to do it twice because the end of the datastream wouldn't output to the file until the next DisplayObjectDetails command was given.  (It works FINE to the interface window, simultaneously.)  So I used regular python file reading commands in a loop to pull out the center set of good data.  I matched and sliced strings to get the SH01, SH02, SH03... data out of the file.  I would still appreciate finding out there was a more elegant way to do this.  But for now my immediate problem is solved and I can keep working on this tool after the holiday break.

Re: Get the sheet that a note resides on using python

In Open C, we would use uc6409().  In .Net, this is wrapped as UFView.AskViewDependentStatus().

 

An object can be view-dependent in a member view, or in the special view that represents the drawing sheet.

 

I checked the Python docs, and this call is also available there as:

NXOpen.UF.View.AskViewDependentStatus()

 

Note that the Python docs mistakenly say "Refer to UF_VIEW_ask_view_dependent_status for documentation", but there is no such function.  It is in the uf_view.h header, but it is called uc6409().

 

Re: Get the sheet that a note resides on using python


SteveLabout wrote:

 

Note that the Python docs mistakenly say "Refer to UF_VIEW_ask_view_dependent_status for documentation", but there is no such function.  It is in the uf_view.h header, but it is called uc6409().

 


Did you file a Docs IR?

:-)

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: Get the sheet that a note resides on using python

 

Hi Ken,

 

Not yet, but I did write to the developer who I think is responsible for the tool that generates those Python docs to see if we have a process problem.  If it is something that is going to require some effort to fix, then he will want a PR to track the problem.  (He is out until next week.)

 

Happy New Year!

 

Steve

 

Re: Get the sheet that a note resides on using python

First, thank you for responding earlier.  Today was my first day back in the office so I could try out your suggestion.  The NXOpen.UF module looks like it has a lot of commands I want to use, but as you noticed the documentation is sparse or wrong for much of it.  I've been able to figure some things out by trial and error, but the UF module's behaviors are beyond me.  The python API seems to be distributed as compiled code (.pyd files) so I can't just look at the source code for hints like you can with the other APIs.

 

Based on your suggestion,  I've tried both

tempViewText = thisNote.NXOpen.UF.View.AskViewDependentStatus()

and

 

tempViewText = NXOpen.UF.View.AskViewDependentStatus(thisNote)

where thisNote is a note Object, and neither returns anything to tempViewText.

 

 

In a related effort, I was trying to get the UserName using NXOpen.UF.Uf.AskSystemInfo() but that throws an exception saying it needs an argument.  The argument required isn't defined by the documentation.  Based on someone's VB code example, I decided to try using a Timer object as the argument.  But the NXOpen.UF.Uf.BeginTimer() also throws an exception saying it needs an argument.  Again, this isn't mentioned or defined in the documentation.  Understanding the syntax in the other programming languages isn't helping me get this module working in python, unfortunately.  (The other modules I've used are not documented like the UF modules are, as in they don't just refer to Open C documentation.)  If you think it is a documentation generation hiccup that can be fixed all at once, that is great.

Re: Get the sheet that a note resides on using python

I just found this page, which explains why the UF module is special:
https://docs.plm.automation.siemens.com/tdoc/nx/10/nx_api#uid:index_nxopen_prog_guide:id1142196:wrap...
I'll start fresh tomorrow with this new perspective - maybe this is the Rosetta Stone I needed to understand UF?

Solution
Solution
Accepted by topic author robin_h_p
‎01-04-2017 09:48 AM

Re: Get the sheet that a note resides on using python

To use the UF wrappers, you must first get the UFSession object, like this:

 

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

    theSession  = NXOpen.Session.GetSession()
    theUFSession = NXOpen.UF.UFSession.GetUFSession()
    workPart = theSession.Parts.Work
    displayPart = theSession.Parts.Display

    lw = theSession.ListingWindow
    lw.Open()
    lw.WriteLine("Points in Part, found by cycling objects.")

    NULLTAG = 0
    objectTag = 0

    objectTag = theUFSession.Obj.CycleObjsInPart(workPart.Tag, NXOpen.UF.UFConstants.UF_point_type, objectTag)

    while objectTag != NULLTAG:
        objType = 0
        objSubType = 0

        objType, objSubType = theUFSession.Obj.AskTypeAndSubtype(objectTag)

        nxPoint = NXOpen.TaggedObjectManager.GetTaggedObject(objectTag)
        lw.WriteLine("Point found at tag {}".format(nxPoint.Tag))
        objectTag = theUFSession.Obj.CycleObjsInPart(workPart.Tag, NXOpen.UF.UFConstants.UF_point_type, objectTag)

    # ----------------------------------------------
    #   Menu: Tools->Journal->Stop Recording
    # ----------------------------------------------
    
if __name__ == '__main__':
    main()
Solution
Solution
Accepted by topic author robin_h_p
‎01-04-2017 09:48 AM

Re: Get the sheet that a note resides on using python

The detailed UF docunmentation is contained in the Open C Reference Guide. This should be used for reference no matter what wrapper language is being used for your application. It is essential to refere to this to be able to provide the correct arguments to the functions. Being open C, the functions typically only return an integer error code. The "real" information you are looking for from the function will be returned via an argument.

 

For example, the AskSystemInfo() function takes a reference to a UF_system_info_t structure. You need to instantiate such an object, then call AskSystemInfo() with this object provided as an argument. Finally, query the updated UF_system_info_t structure to access the information.

 

https://docs.plm.automation.siemens.com/data_services/resources/nx/11/nx_api/custom/en_US/ugopen_doc...

 

https://docs.plm.automation.siemens.com/data_services/resources/nx/11/nx_api/custom/en_US/ugopen_doc...