Home > Back-end >  How can I convert a tag_t to an NXOpen::NXObject in NX Open C ?
How can I convert a tag_t to an NXOpen::NXObject in NX Open C ?

Time:11-01

I have a tag_t returned from an NX Open C API call, and I want to use it in an NX Open C API call, but the C API call uses an NX Open class, e.g. NXOpen::NXObject or NXOpen::Part.

How can I convert this tag_t into an NXOpen::NXObject?

CodePudding user response:

Use nxopen.TaggedObjectManager in Java, and you must get an instance of it from the nxopen.Session class:

Tag myTag = ...;

Session session = (Session)SessionFactory.get("Session");
TaggedObject myObj = session.taggedObjectManager().get(tag);

Part myPart = (Part)myObj;
// Do something with myPart...

CodePudding user response:

In C#, NXObjectManager is in the NXOpen.Utilities namespace:

NXOpen.Tag tag = ...;
NXOpen.TaggedObject myObj = NXOpen.Utilities.NXObjectManager.Get(myTag);

Part myPart = (Part)myObj;
// Do something with myPart...

CodePudding user response:

NXOpen::NXObjectManager::Get was specifically designed for this. It returns an NXOpen::TaggedObject*, which needs to be dynamic_cast<>ed to the appropriate type.

tag_t myTag = ...;
NXOpen::TaggedObject *myObj = NXOpen::NXObjectManager::Get(myTag);

// Cast it to the appropriate type:
NXOpen::Part* myPart = dynamic_cast<NXOpen::Part*>(myObj);
// Do something with myPart...
  • Related