cancel
Showing results for 
Search instead for 
Did you mean: 

Enrich NX Files with XML Data

Creator
Creator

Hey Folks, I have a rather unusual Idea that I would like to get your thoughts on:

 

We have a Program running that delivers Data for us that we then use to build up our 3D Models. The Program saves it's information to a XML File. In order to Link together this XML File and the resulting 3D Models, i want to implement a Macro that stores this XML File directly inside the 3D Model.

 

My initial approach was to add the XML as a Text to a Parameter or a Expression, but neither of those allow me to store such long strings. I also thought about just opening the File with a word editor and adding the Code there, but that seems a stupid idea, seeing as those files are binary and i do not wand to corrupt the whole file.

 

I know this sounds like I am bending NX to do something it's not there for, but to us, it really makes sense to store this information right there.

 

Can you think of any Way that I could append this Info directly to the Model?

 

thanks a lot for your help!

 

Best Regards

Franz

12 REPLIES

Re: Enrich NX Files with XML Data

Phenom
Phenom

I've done something similar, using attributes on an object. My code had took a set of strings (some too long for an attribute, others short enough) and added each on as an attribute to an object. The attribute names had a numeric suffix, so they could be retrieved in order.

For the long strings that could not be added they were split into two or more parts and a special continuation character added at the start/end where they had been split. The characters I chose to use were '»' at the end of strings that had been shortened and '«' at the start of the string where the beginning had been cut off.

For example suppose one string was "The quick brown fox jumped over the lazy dog" and the maximum string length for an attribute was 20. I would add attributes as follows:

ATTR_001 = "The quick brown fox»"
ATTR_002 = "« jumped over the l»"
ATTR_003 = "«azy dog"

Then to read the string back later on some other code read all of the attributes in order, located any "»" and "«" characters and concatenated the strings back together.

Choice of the special characters is key here, "»" and "«" are not common and don't appear on a keyboard so I could reasonably expect them not to appear in the strings (especially as I defined the strings in the first place Man Wink).

Maybe you could employ something similar? You could use part attributes if you don't want to tie the data to a specific NX object.

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: Enrich NX Files with XML Data

Siemens Phenom Siemens Phenom
Siemens Phenom

Your other choice is user defined objects.  This is a large topic, and not suitable to try to explain in a forum post, but you can read about them in the NX Open Programmer's Guide.  They have their own chapter.  8-)

 

Re: Enrich NX Files with XML Data

Phenom
Phenom

I've also used UDOs to store string data. UserDefinedObject has setStrings() and getStrings() methods.

But as Steve said, using UDOs is non-trivial and cannot be fully covered in here.

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: Enrich NX Files with XML Data

Creator
Creator

Sorry, I was away for a week and just now came back to find your suggestions.

Thank you so much for your help!

 

I think i will try and go with the UDO's, i have found a nice sample Programm in the NXOpen Folder that i have modified to store my Info in, works like a charm!

 

My Problem though is with data permanence. Once i save the NX part, close NX and reopen it, the UDO is gone =(

Do you know what i need to do to permanently save a UDO in a Part?

 

Thanks a bunch for your suggestions!

Re: Enrich NX Files with XML Data

Phenom
Phenom

Once you've create a UDO in the part it should get saved with the part. The key is finding it again next time.

Not sure which example you are using as a basis for your code, so I don't know if it shows how to find an existing UDO, but the basic principle is to find all UDO's of your UDO class type in the part.

To do this you can use UserDefinedObjectManager's getUdosOfClass() method. This will return an array of UDOs in the part of that class type.

If you create more than one UDO of the same class type, then you need to implement some way to tell them apart. For this I've usually used the first string in the Strings member to hold a name for that instance.

You could equally use the Integers and set the first Integer to a counter so each instance of the UDO gets a different index.

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: Enrich NX Files with XML Data

Siemens Phenom Siemens Phenom
Siemens Phenom

 

Without the custom code that defines or registers the UDO class, NX doesn't know anything about your UDO.

 

The common process is to have a .DLL that runs at startup to define the class.  You can put this in the "udo" folder for simplicity.  This should be explained clearly in the docs, but you might need to poke around a bit.

Re: Enrich NX Files with XML Data

Creator
Creator

Thanks Steve,

I think that's the issue that was bothering me. I had started reading the Programmer's Guide Section, but go so excited with UDO's that i started coding before finishing the Read =D

Thanks again!

Re: Enrich NX Files with XML Data

Phenom
Phenom

For simple data storing UDOs it's not actually necessary to have a DLL run at startup to register the class.

In my code whenever I look for a UDO like this I use UserDefinedClassManager.getUserDefinedClassFromClassName() to get the class. If it has not been registered yet this throws an Exception with error code 1535022 which I catch. In this case I then use UserDefinedClassManager.createUserDefinedObjectClass() to create it.

Because the class has no functionality other than defining the UDO type, it does not need to be registered at startup time.

 

Yes, I know using exceptions to handle logic is bad practice, but it means I can keep all of the UDO code in one place and not have to have a separate DLL (or JAR, I'm using Java) get executed at startup.

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: Enrich NX Files with XML Data

Siemens Phenom Siemens Phenom
Siemens Phenom

Graham is absolutely correct.  As is often the case in NX, there is more than one perfectly valid way to approach this.  That is why I wrote "The common process is...", and not something indicating that the described method was required.  UDO's are really flexible, and really powerful, and initially, they may seem really complicated.

 

If you want to use a particular class of UDO in a lot of parts, it might be easier to have the class get registered at startup.  If you only want to use them on an occasional basis, then the other method might work better for you.  It's nice to have the choice!  8-)