cancel
Showing results for 
Search instead for 
Did you mean: 

Block UI Styler : Extracting the body tag (NX Open C++)

Experimenter
Experimenter

I am trying to use the C++ template generated using Block UI Styler (Body Collector) for an application. I am currently using the following method to extract the body tag of a selected body. I wanted to know if there was an easier / more efficient way of extracting just the body tag of the selected solid?

Thanks.

 

std::vector<NXOpen::TaggedObject*> blockList = bodySelect0->GetProperties()->GetTaggedObjectVector("SelectedObjects");
Body *List_body = (Body *) blockList[0];
const tag_t selBody = List_body->Tag();
7 REPLIES

Re: Block UI Styler : Extracting the body tag (NX Open C++)

Siemens Phenom Siemens Phenom
Siemens Phenom

That's pretty much what you have to do. One minor point: you don't really have to cast the selected object to Body to get it's tag:

 

std::vector<NXOpen::TaggedObject*> blockList = bodySelect0->GetProperties()->GetTaggedObjectVector("SelectedObjects");
const tag_t selBody = blockList[0]->Tag();

Re: Block UI Styler : Extracting the body tag (NX Open C++)

Solution Partner Genius Solution Partner Genius
Solution Partner Genius

You can do it directly like this

 

vector<TaggedObject*> blockList = bodySelect0->GetSelectedObjects()

const tag_t selBody = blockList[0]->Tag();

 

Re: Block UI Styler : Extracting the body tag (NX Open C++)

Experimenter
Experimenter

Thank you for the replies.

 

I just wanted to ask a follow-up question.

What other properties of the selected body are being stored in the vector, blockList?

 

 

Re: Block UI Styler : Extracting the body tag (NX Open C++)

Siemens Phenom Siemens Phenom
Siemens Phenom

I'm not sure that you understand what you are asking.

 

You code declares blockList as a vector (i.e. an array) of objects of type NXOpen::TaggedObject

 

blockList is simply a vector containing objects. It's properties are the vector length/count of number of objects stored in the vector.

 

blockList[0] refers to a particular (the first) object in the vector. blockList[0] is a NXOpen::TaggedObject. It inherits properties from that class. The available properties depend on the class of the object in the vector (i.e. NXOpen::TaggedObject), not the vector itself.

 

Your original code cast this blockList[0] object to a NXOpen::Body type object (List_body). This object inherits properties from both NXOpen::TaggedObject and NXOpen::Body.

Re: Block UI Styler : Extracting the body tag (NX Open C++)

Experimenter
Experimenter

Hello @JimB

 

I understand that blockList is a vector of objects of class TaggedObjects. 

 

What I wanted to know was, since

const tag_t selBody = blockList[0]->Tag();

returns a tag of the selected body then if I used, 

 

const tag_t selBody = blockList[1]->Tag();

or

const tag_t selBody = blockList[2]->Tag();

 

what object would the returned tags be associated with? 

 

 

Re: Block UI Styler : Extracting the body tag (NX Open C++)

Siemens Phenom Siemens Phenom
Siemens Phenom

This would assume that 3 (or more) bodies were selected by the user. This implies that the SelectMode property of the Block Styler SelectObject block is set to "Multiple". If Select Mode is set to Single, then GetTaggedObjectVector() would only return a single item in the array.

 

If multiple selection is allowed (and multiple objects were selected), then blockList[1]->Tag() would be the tag of the second body in the list, blockList[2]->Tag() woudl be the tag of the third body in the list, etc.

 

Note that the order of the objects in the vector does not necessarily correspond to the order that the user selected the bodies in.

 

If multiple selection is allowed, you should always check the length of the TaggedObject vector and proceed accordingly in your application.

Re: Block UI Styler : Extracting the body tag (NX Open C++)

Experimenter
Experimenter
Thank you for the explanation.