Cancel
Showing results for 
Search instead for 
Did you mean: 

Persistent Object Identifier

Experimenter
Experimenter

I am writing a plugin for NX CAE that would track metadata for certain elements in order to automatically post-process.

 

So, for instance, I'd need to know that MeshCollector MC1 is associated with a 1/4-20 screw, and I'd need to keep this knowledge if the user renamed the mesh collector and the file.

 

In order to do that, I want to get certain NXobjects, (e.g., FemParts, MeshCollectors, and BoltBuilders) robustly across sessions.

 

Our coop this with Journal IDs, but this is very clumsy and explicitly discouraged in the documentation

 

Tags are apparently not uique to the TaggedObject, but somehow related to the session.

 

I have tried setting attributes in a number of different ways, but this always reults in NX throwing and exception.

 

Any help is appreciated.

12 REPLIES

Betreff: Persistent Object Identifier

Legend
Legend
Attributes should work. Try to figure out what is going wrong in your case. Give more details what you tried and what exception you get.

Regards,
Jan
Jan Böttcher

Betreff: Persistent Object Identifier

Experimenter
Experimenter

Thanks.

 

I should have mentioned this is C# dotnet.

 

Here is enough code to reproduce the problem. I also went ahead and attached the associated FEM.

 

using System;
using System.Collections.Generic;
using System.Windows;
using NXOpen;
using NXOpen.CAE;
using static NXOpen.UF.UFSf;			
			
namespace RoseNX
{  
    public partial class NXMain
    {
        public static void Main(string[] args)
        {
	    theSession = Session.GetSession();		
	    workFemPart = (FemPart)theSession.Parts.BaseWork;		
	    currentFeModel = (FEModel)workFemPart.FindObject("FEModel");
			
	    // This works fine and sets a user attribute that is visible in
// the .fem file properties workFemPart.SetUserAttribute("RoseID", 0, 5, Update.Option.Now); MeshManager meshManager = (MeshManager)currentFeModel.MeshManager; var collectors = meshManager.GetMeshCollectors();            var collector = collectors[0];            // This throws the exception below            collector.SetUserAttribute("RoseID", 0, 5, Update.Option.Now); } } }

Capture.PNG

Betreff: Persistent Object Identifier

I think this is what handles are for. Pretty much like a Tag, but persistent across sessions. Get them using UF.Tag functions:

 

https://docs.plm.automation.siemens.com/data_services/resources/nx/12/nx_api/custom/en_US/nxopen_pyt...

Nikolas Losse | Developer | Siemens PG PR R&D TEC
NX12 | CentOS7 | Python

Betreff: Persistent Object Identifier

Experimenter
Experimenter

Thanks,

This looks like what I am looking for, but these methods are not static, and I can't find any constructor for NXOpen.UF.UFTag. How do I create a UFTag?

Michael Pogue
Project Engineer
ATA Engineering
858-480-2128

Betreff: Persistent Object Identifier

In Python it's like this

 

handle = NXOpen.UF.Tag().AskHandleOfTag(object.Tag)
Nikolas Losse | Developer | Siemens PG PR R&D TEC
NX12 | CentOS7 | Python

Betreff: Persistent Object Identifier

Legend
Legend

Any class that inherits from TaggedObject has a property 'Tag' that can be used as input for the UF functions.

 

Regards

Jan

Jan Böttcher

Betreff: Persistent Object Identifier

One caveat when using handles:

 

The file name is part of the handle.

 

This means that when you rename the file, the handle has to change too.

 

You can work around this by using the DecomposeHandle function to get the three parts of your handle, replace the file_data part and use ComposeHandle to stick it back together.

 

See also here

 

 

Nikolas Losse | Developer | Siemens PG PR R&D TEC
NX12 | CentOS7 | Python

Betreff: Persistent Object Identifier

Experimenter
Experimenter

It does not appear to be like this in dotnet. These functions are in the NXOpen.UF.UFTag class, which is not static. So I have to create an instance of a UFTag. There are no public constructors and I have no idea how to get an instance.

Betreff: Persistent Object Identifier

Experimenter
Experimenter

OK, found it--sample below for future ref.

 

Boy, if you didn't know this stuff, I don't know how you'd know this stuff.

 

 

NXOpen.UF.UFSession ufSession = NXOpen.UF.UFSession.GetUFSession();

ufSession.Tag.AskHandleFromTag(bolt.Tag, out string handle);