iCAx开思工具箱
标题:
不通过遍历如何获取布尔运算后的面的面积(UG8.0 + VS2010)
[打印本页]
作者:
cqhuang
时间:
2012-9-5 10:21
标题:
不通过遍历如何获取布尔运算后的面的面积(UG8.0 + VS2010)
经过几个月的业余学习,对OPEN C和NXOPEN C++作了对比,发现NX OPEN C++十分实用,通过UG内置的日志录取功能,可以很快速的找到功能的实现方法,结合BlockUI开发的界面,很容易的实现UG二次开发功能。
由于工作中要对一个移动面与固定的多个面进行重复布尔相交运算,并获取相交后的相交面的面积的功能,BlockUI 界面和布尔运算函数和求面积的函数都已经完成。但在获取相交面的过程中出现问题,根据布尔相交提交的结果,获取的NXObject * 对象,不能获取相交平面。(由于进行布尔运算相交的面的数量比较多,如果都通过遍历来得到相交面,我想效率是十分低的,所以放弃了), 但想想通过OPEN C 的UF_MODL_intersect_bodies_with_retained_options 命令都能轻松的获取tag_t 标识,为什么NX OPEN C++ 就这么困难呢? 这个问题纠结了我1个星期。
希望NX OPEN C++ 高手指点一下,如何获取布尔交后的Body *或Face *,感激不尽。
附上我自己做的实现布尔交和获取面积的函数。
Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
//--------------------布尔交运算函数(保留目标和刀具)-----------------------
void bool_inter(Body* body01,Body* body02)
{
Features::BooleanFeature *nullFeatures_BooleanFeature(NULL);
Features::BooleanBuilder *booleanBuilder1;
booleanBuilder1 = workPart->Features()->CreateBooleanBuilderUsingCollector(nullFeatures_BooleanFeature);
ScCollector *scCollector1;
scCollector1 = booleanBuilder1->ToolBodyCollector();
booleanBuilder1->SetTolerance(0.001);
booleanBuilder1->SetCopyTargets(true);
booleanBuilder1->SetCopyTools(true);
booleanBuilder1->SetOperation(Features::Feature::BooleanTypeIntersect);
bool added1;
added1 = booleanBuilder1->Targets()->Add(body01);
ScCollector *scCollector2;
scCollector2 = workPart->ScCollectors()->CreateCollector();
std::vector<Body *> bodies1(1);
bodies1[0] = body02;
BodyDumbRule *bodyDumbRule1;
bodyDumbRule1 = workPart->ScRuleFactory()->CreateRuleBodyDumb(bodies1);
std::vector<SelectionIntentRule *> rules1(1);
rules1[0] = bodyDumbRule1;
scCollector2->ReplaceRules(rules1, false);
booleanBuilder1->SetToolBodyCollector(scCollector2);
NXObject *nXObject1;
nXObject1 = booleanBuilder1->Commit();
booleanBuilder1->Destroy();
}
//--------------------获取面的面积-----------------------
void area(Face* face01,double* AreaResult)
{
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("SquareMilliMeter")));
Unit *unit2(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
std::vector<IParameterizedSurface *> objects1(1);
objects1[0] = face01;
MeasureFaces *measureFaces1;
measureFaces1 = workPart->MeasureManager()->NewFaceProperties(unit1, unit2, 0.99, objects1);
AreaResult [0] = measureFaces1->Area();
delete measureFaces1;
}
作者:
cqhuang
时间:
2012-9-5 12:52
终于找到方法了
,原来转换出错了,现把整个实现函数发上来,供大家参考,若有其他更好方法的,请不吝赐教,谢谢
//--------------------布尔交运算函数-----------------------
void bool_inter(Body* body01,Body* body02,double* data)
{
Features::BooleanFeature *nullFeatures_BooleanFeature(NULL);
Features::BooleanBuilder *booleanBuilder1;
booleanBuilder1 = workPart->Features()->CreateBooleanBuilderUsingCollector(nullFeatures_BooleanFeature);
ScCollector *scCollector1;
scCollector1 = booleanBuilder1->ToolBodyCollector();
booleanBuilder1->SetTolerance(0.001);
booleanBuilder1->SetCopyTargets(true);
booleanBuilder1->SetCopyTools(true);
booleanBuilder1->SetOperation(Features::Feature::BooleanTypeIntersect);
bool added1;
added1 = booleanBuilder1->Targets()->Add(body01);
ScCollector *scCollector2;
scCollector2 = workPart->ScCollectors()->CreateCollector();
std::vector<Body *> bodies1(1);
bodies1[0] = body02;
BodyDumbRule *bodyDumbRule1;
bodyDumbRule1 = workPart->ScRuleFactory()->CreateRuleBodyDumb(bodies1);
std::vector<SelectionIntentRule *> rules1(1);
rules1[0] = bodyDumbRule1;
scCollector2->ReplaceRules(rules1, false);
booleanBuilder1->SetToolBodyCollector(scCollector2);
NXObject *nXObject1;
nXObject1 = booleanBuilder1->Commit();
std::vector<NXObject *> selectedObjects1(1);
Features::BooleanFeature *booleanFeature1(dynamic_cast<Features::BooleanFeature *>(nXObject1));
selectedObjects1[0] = booleanFeature1;
std::vector<Body *> selectedBody;
selectedBody = booleanFeature1->GetBodies();
std:;vector<Face *>face03;
face03 = selectedBody[0]->GetFaces();
//----------获取面积数据----------------------
Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("SquareMilliMeter")));
Unit *unit2(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
std::vector<IParameterizedSurface *> objects1(1);
objects1[0] = face03[0];
MeasureFaces *measureFaces1;
measureFaces1 = workPart->MeasureManager()->NewFaceProperties(unit1, unit2, 0.99, objects1);
data[0] = measureFaces1->Area();
delete measureFaces1;
//--------------------------------------------
booleanBuilder1->Destroy();
}
作者:
136020036
时间:
2012-10-10 11:37
我之前用VS2010开发NX7.5,.NET是2.0,但是开发8.0时需要.NET4.0,我的电脑业安装了.NET4.0就是不能自动引用.NET4.0,为什么啊???
欢迎光临 iCAx开思工具箱 (https://t.icax.org/)
Powered by Discuz! X3.3