Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

NX Journal to get a feature's associated body

Status
Not open for further replies.

TheWenger

Aerospace
Apr 25, 2013
16
I'm trying to write a journal that let's me select a feature and grab the body associated with that feature so I can do a DisplayModification to it. I tried to record a journal to see how NX does it when you press CTRL + J with a feature selected, but uses sticky references and I can't figure out. Anyone have ideas?
 
Replies continue below

Recommended for you

If you have a reference to a feature object, you can use the .GetEntities method to return an array of objects created by the feature. Face and Edge objects have a .GetBody method that will return the body that contains the face/edge. So, as long as the chosen feature creates a face/edge, you should be able to get at the parent body.

As an alternative, why not just prompt the user to select the body? Why does it have to be a feature that is selected?

www.nxjournaling.com
 
Thanks. I'll give that a try tomorrow. It's nice coding in Visual Studio with the NXOpen references added.

The way the journal is going to work is that if there is no selection at runtime, it'll prompt for a selection and filter it to bodies or components. If there is already a selection, and the selection is a feature (extrude, hole, etc.) it'll get the associated solid and apply the modification on it.
 
So I'm doing

Code:
Dim selectedFeature As Features.Feature = CType(selected, Features.Feature)
Dim selectedEntities As NXObject() = selectedFeature.GetEntities
Dim selectedFace As Object = selectedEntities.GetValue(0)
Dim selectedBody As Body = selectedFace.GetBody

But I get an error when running with the third line in that block. It says the index is outside the bounds of the array, which makes me think the array returned from .GetEntities is empty. I've also tried selectedEntities.First and it just says there is no First in the array.
 
I've been tinkering with it a bit and it seems .GetEntities returns empty no matter what. I'd suggest searching GTAC solutions for a working code sample.
If there is no sample, perhaps a call to GTAC to see if .GetEntities is working as designed, and maybe they can whip up a sample and/or provide a workaround.

www.nxjournaling.com
 
Features covers much more than features that have bodies. Therefore you first have to get the BodyFeature that the feature must have to get the body/bodies. Then using the bodyfeature you can use GetBodies(). Check BodyFeature Class.

Frank Swinkels
 
Frank, that worked perfectly. Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor