cancel
Showing results for 
Search instead for 
Did you mean: 

Exception when retrieving saved UDO

Solution Partner Experimenter Solution Partner Experimenter
Solution Partner Experimenter

I am getting an "exception" -- "You do not have permission to query this class id."

when trying to access a saved UDO.

 

Exception is thrown at call

"theSession.UserDefinedClassManager.GetUserDefinedClassFromClassName("MYUDO")"

 

This only happens when its a new NXSession (UI is closed and re-opened), in the same session when a document is closed and re-opened the exception is not thrown and I am able to access the saved UDO.

 

"AllowQueryClassForName" is also "ON" during save.

udoclass.AllowQueryClassFromName = UserDefinedClass.AllowQueryClass.On;

5 REPLIES

Re: Exception when retrieving saved UDO

Esteemed Contributor
Esteemed Contributor

I'm guessing...

You don't have enough code (or any) that is run when NX starts.

Note UDEOs require some code to register the UDO with NX, and handle the proper callbacks, so NX knows what to do.

Offhand, I don't remember what has to be where (startup code vs. application code) but there should be some docs for that somewhere...

Ken

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: Exception when retrieving saved UDO

Phenom
Phenom

This isn't entirely true @Ken_A, you only need code executing at NX startup if you want to be able to handle callbacks for the UDO. If the UDO is completely dumb it is quite OK to create it without any code running at startup.

I use this method to create UDOs to simply store data in the part between executions of my BlockStyler code. I can put object links, strings, doubles etc in the UDO and pick them up again next time someone executes my BlockStyler program.

I just looked at the code where I do this and when I call getUserDefinedClassFromClassName() I catch NXExceptions and check the error code. If it is 1535022 then I presume the class has not been defined yet and then define it. Its too long ago since I did this to recall if 1535022 equates to "You do not have permission to query this class id.", but possibly.

Anyway, here's the method I use to get the UserDefinedClass. First time it will catch that exception and define it, otherwise it will find it and return the already existing definition.

(Note this is Java and we are using dependency injection so where you see udcMgrProv.get() it is simply getting an injected instance of UserDefinedClassManager)

private UserDefinedClass getLinkUdc() {
  try {
    UserDefinedClass udc;
    try {
      udc = udcMgrProv.get().getUserDefinedClassFromClassName(OBJECT_LINK_CLASS_NAME);
    } catch (NXException nxe) {
      if (nxe.errorCode() == 1535022) {
        udc = null;
      } else {
        throw (nxe);
      }
    }
    if (udc == null) {
      udc = udcMgrProv.get().createUserDefinedObjectClass(OBJECT_LINK_CLASS_NAME, OBJECT_LINK_CLASS_FRIENDLY_NAME);
      udc.setAllowQueryClassFromName(AllowQueryClass.ON);
    }
    return udc;
  } catch (Exception e) {
    throw new YappException(e);
  }
} 

 

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: Exception when retrieving saved UDO

Solution Partner Experimenter Solution Partner Experimenter
Solution Partner Experimenter

@@Inch

"try catch" block Idea is working perfectly fine for me. Thank You.

 

I have an application which uses "UDO" ( saved in part / document ) to save selection's made.

Currently I am saving TAGS of the bodies / components selected, and re-reading them from UDO, after

part / documet is re-opened.

 

Is this safe ?

I came across another discussion where its mentioned the TAGS are not persitstant across sessions.

https://community.plm.automation.siemens.com/t5/NX-Programming-Customization/Recognizing-NX-Body-aft...

 

Should I be using something else ?

 

I had no problem re-reading the saved TAGS inside UDO, even after re-naming the part file, hence I am

confused.

Re: Exception when retrieving saved UDO

Phenom
Phenom

I think the statement about tags says they are not guaranteed to be persistent between sessions, so often times while I'm debugging my code I can see that tags are identical each time. But eventually you will find that the tags change between sessions.

If you are storing data in a UDO there is a really nice feature you can use and that is links in the UDO to objects. These do not use tagsand are guaranteed to persiste between sessions.

There are different ways to create these links so if the UDO gets deletes the objects that are linked can be handled in different ways. I use UserDefinedObject.LinkType.TYPE4 which means:

"If the UDO is deleted the link between the UDO and the associated object is removed and the object is unaffected."

Have a look into UDO object links, I find them really useful for finding objects between sessions in a way that the interactive user cannot disrupt (like object names, attributes etc).

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: Exception when retrieving saved UDO

Solution Partner Experimenter Solution Partner Experimenter
Solution Partner Experimenter

Okay,

 

Thanks again, I will try that out.