Cancel
Showing results for 
Search instead for 
Did you mean: 

Getting volume of solid created from ruled body

Siemens Pioneer Siemens Pioneer
Siemens Pioneer

Hi,

 

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)")));
features1.push_back(ruled1);

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;
measureBodyBuilder1->Destroy();

 

--------------------------------------------------------------------------------------------------------------------

 

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

 

3 REPLIES

Re: Getting volume of solid created from ruled body

Honored Contributor
Honored Contributor

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.

 

http://solutions.industrysoftware.automation.siemens.com/view.php?si=pr-7176007

Re: Getting volume of solid created from ruled body

Siemens Pioneer Siemens Pioneer
Siemens Pioneer

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?

 

Thanks!

Re: Getting volume of solid created from ruled body

Honored Contributor
Honored Contributor

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.