cancel
Showing results for 
Search instead for 
Did you mean: 

Recognizing NX Body after session closed

Siemens Pioneer Siemens Pioneer
Siemens Pioneer

Hi,

 

I am developing an application (NXopen c++) that takes a body from user input, then the part is saved. After that the session will be closed to perform some other operations. Then, the previously saved  part is re-opened, and additional operations are performed on the body selected in the first step.

 

In the first step, I need to some how saved the tag of the body selected by the user, so that it can be reused in th last step. I am thinking to use the name of the body to recognize the body in the last step. But NX body does not has a name variable. Anyone has suggestions? I tried using Feature name, but if I use GetFeatures on the selected body, I get the parent features for extract body type, which is not what I am looking for.

 

Thanks!

 

 

13 REPLIES

Re: Recognizing NX Body after session closed

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

Hi Elaine,

 

You have two solutions, one simple and one more complicated:

 

1) Simple Solution: Set a string attribute to the body in the first step: body->SetAttribure("Title", "My_Body"). In the second step, loop through all bodies and check which one has the attribute by using the GetStringUserAttribute function: body->GetStringUserAttribute("Title", -1).

 

2) More tricky solution: Create a User Defined Object (UDO) that store a link to the body. You can define 5 types of links. The UDO will be saved in your part. When opening the part, ask for the UDO and get its link. You will then get the bofy from the link.

 

Elias.

Re: Recognizing NX Body after session closed

Valued Contributor
Valued Contributor

Hello Elaine,

 

you can move the selected body to a specific layer which is not used by other bodies/geometry and than scan this layer after reopening the part.

 

But like Elias mentioned, setting an attribute to the body is maybe the easiest way.

 

Greez

Herbert Macho
EBNER Industrieofenbau
AUSTRIA

NX10.0.3.5 (TeamCenter10 and Native)

Re: Recognizing NX Body after session closed

Honored Contributor
Honored Contributor

You can get the "handle" of the object, which is persistent between sessions (tags are not persistent). The .AskHandleOfTag and .AskTagOfHandle functions will help here.

Re: Recognizing NX Body after session closed

Siemens Phenom Siemens Phenom
Siemens Phenom

The original idea of using the name seems like a good solution here.  You can use the tag of the body to specify a name.  The Open C function would be UF_OBJ_set_name().  If you are working in .Net, you can use the wrapper, so it would look something like this:

 

theUFSession.Obj.SetName(theBody.Tag, "TheBodyName");

Re: Recognizing NX Body after session closed

Honored Contributor
Honored Contributor

In .net, if you have a reference to the body object, you can set its name with the body's .SetName method:

{body object variable}.SetName("some_name")

 And access it later with the .Name property:

If {body object variable}.Name = "some_name" Then
...

If you go this route, you will need to make sure that the name you give it is unique; otherwise, you run the risk of accessing the wrong body later in your code.

Re: Recognizing NX Body after session closed

Siemens Phenom Siemens Phenom
Siemens Phenom

Actually you will need to use "SetName" to assign a name to the Body object.  The Name property "Returns the custom name of the object".  (As opposed to, "returns or sets".)

 

But the main thing is that the original thought about using a name to find the object is probably the simple solution!

Re: Recognizing NX Body after session closed

Honored Contributor
Honored Contributor

SteveLabout wrote:

Actually you will need to use "SetName" to assign a name to the Body object.  The Name property "Returns the custom name of the object".  (As opposed to, "returns or sets".)

 

But the main thing is that the original thought about using a name to find the object is probably the simple solution!


I edited my post right before I saw your correction.

 

I agree that using a name is a "quick and dirty" solution, but you would really need to iterate through the body collection to make sure no other body has the name you intend to use. The probability that another body already has the name is low, but not zero, even on the first run of your code. If you forget to remove the name or your code errors out before the name is removed, and you run the code multiple times on the same part, the probability greatly increases.

 

Using the system generated handle is very similar to using a unique name. When you consider the bookkeeping and error checking code that it would eliminate, I'd argue that it is actually easier (and safer) to use in the long run.

Re: Recognizing NX Body after session closed

Phenom
Phenom

As long as you're not using Teamcenter.. I don't recall exactly the issue we found, but I think the handles are pretty useless in this scenario.

Also be aware that if the part file name is changed all of the handles will change too as they contain the part file name. So you cannot record a handle and expect to find it again if the part has been renamed in the meantime.

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: Recognizing NX Body after session closed

Esteemed Contributor
Esteemed Contributor

Graham -

I'm guessing... that the part file name includes the item rev when working in Teamcenter.

So as soon as you "Save As" to a new revision, the "part file name" changes, so that would break all the handles?

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