Showing results for 
Search instead for 
Do you mean 
Solved! Go to solution

Getting volume of solid created from ruled body



I want to get the volume of a solid created from ruled surfaces. I used NX journaling and has come up with the following code in NX open (C++):



Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());

NXObject *nullNXObject(NULL);
MeasureBodyBuilder *measureBodyBuilder1;
measureBodyBuilder1 = workPart->MeasureManager()->CreateMeasureBodyBuilder(nullNXObject);

std::vector<Features::Feature *> features1;
Features::Ruled *ruled1(dynamic_cast<Features::Ruled *>(workPart->Features()->FindObject("RULED(10)")));

BodyFeatureRule *bodyFeatureRule1;
bodyFeatureRule1 = workPart->ScRuleFactory()->CreateRuleBodyFeature(features1, true);

std::vector<SelectionIntentRule *> rules1(1);
rules1[0] = bodyFeatureRule1;
measureBodyBuilder1->BodyCollector()->ReplaceRules(rules1, false);

std::vector<Unit *> massUnits1(5);
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("SquareMilliMeter")));
massUnits1[0] = unit1;
Unit *unit2(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("CubicMilliMeter")));
massUnits1[1] = unit2;
Unit *unit3(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("Kilogram")));
massUnits1[2] = unit3;
Unit *unit4(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
massUnits1[3] = unit4;
Unit *unit5(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("Newton")));
massUnits1[4] = unit5;

MeasureBodies *measureBodies1;
measureBodies1 = workPart->MeasureManager()->NewMassProperties(massUnits1, 0.99, measureBodyBuilder1->BodyCollector());


Measure *measure1;
measure1 = measureBodies1->CreateFeature();

double PartVol = measureBodies1->Volume();

delete measureBodies1;




I ran this .dll and the NX GUI did show the volume, surface area, and other parameters in a box.

However, in the c++ program, the variable "PartVol" gives zero.

Why is that? Is there any easier way to get volume of a body/ruled solid?


Thanks! Cat Happy


Accepted by topic author ElaineT
‎03-04-2016 11:21 AM

Re: Getting volume of solid created from ruled body

What version of NX?


There is a bug in versions before NX 10, where the measure bodies object returns 0 if a body collector is used. However, if you pass an array of bodies instead of using a collector, it works as expected.

Re: Getting volume of solid created from ruled body

It worked like a charm!!!! Thank you so much!


Now I realized I run into another issue. I also need to calculate the volume of an object which is a "Subtract" (Boolean) object. I tried with a similar approach but this time it doesn't work.


I think the reason might be that a "Subtract" object is not a "Body" Object. Any suggestion on this?



Accepted by topic author ElaineT
‎04-26-2016 06:19 PM

Re: Getting volume of solid created from ruled body

If you want to get the 'target' body of the subtract operation, you can use the .GetBodies method of the boolean feature. This should get you a reference to the body that results from the subtract operation.