C++
//用户头文件
#include <uf_ui.h>
#include <NXOpen/Body.hxx>
#include <NXOpen/BodyCollection.hxx>
#include <NXOpen/BodyDumbRule.hxx>
#include <NXOpen/Builder.hxx>
#include <NXOpen/DisplayableObject.hxx>
#include <NXOpen/Features_BooleanBuilder.hxx>
#include <NXOpen/Features_FeatureCollection.hxx>
#include <NXOpen/GeometricUtilities_BooleanRegionSelect.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/DisplayableObject.hxx>
#include <NXOpen/GeometricUtilities_BooleanRegionSelect.hxx>
#include <NXOpen/ScCollectorCollection.hxx>
#include <NXOpen/SelectBodyList.hxx>
#include <NXOpen/ScRuleFactory.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/NXObjectManager.hxx>
//设置过虑(注释处改动即可使用)
Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
std::vector<Selection::MaskTriple> maskArray(1);
maskArray[0] = Selection::MaskTriple( UF_solid_type, UF_solid_body_subtype/*此处控制选择的类型,右键点转到
定义查开类型*/, UF_UI_SEL_FEATURE_SOLID_BODY /*此处控制选择的类型,在头文件uf_ui_types.可以查到*/ ); // Bodies
selection01/*此处blockID需按实际改*/->GetProperties()->SetSelectionFilter
("SelectionFilter",action,maskArray);
selection02/*此处blockID需按实际改*/->GetProperties()->SetSelectionFilter
("SelectionFilter",action,maskArray);
//用户代码
//获取枚举UI界面值
PropertyList *enum0Props = enum0->GetProperties();
int EnumValue = enum0Props->GetEnum("Value");
delete enum0Props;
enum0Props = NULL;
Session *theSession = Session::GetSession(); //获取绘画客口
Part *workPart = theSession->Parts()->Work(); //获取工作部件
Part *displayPart = theSession->Parts()->Display(); //获取显示部件
//布尔
Features::BooleanFeature *nullFeatures_BooleanFeature(NULL);
Features::BooleanBuilder *booleanBuilder1;
booleanBuilder1 = workPart->Features()->CreateBooleanBuilderUsingCollector(nullFeatures_BooleanFeature);
ScCollector *scCollector1;
scCollector1 = booleanBuilder1->ToolBodyCollector();
GeometricUtilities::BooleanRegionSelect *booleanRegionSelect1;
booleanRegionSelect1 = booleanBuilder1->BooleanRegionSelect();
booleanBuilder1->SetTolerance(0.001);
//判断
if ( EnumValue == 0 )
{
booleanBuilder1->SetOperation(Features::Feature::BooleanTypeUnite);//设置布尔加
}
else if ( EnumValue == 1 )
{
booleanBuilder1->SetOperation(Features::Feature::BooleanTypeSubtract);//设置布尔减
}
else if ( EnumValue == 2 )
{
booleanBuilder1->SetOperation(Features::Feature::BooleanTypeIntersect);//设置布尔交
}
//获取UI选择的第一个体
PropertyList* selection01Props = selection01->GetProperties();
std::vector<NXOpen::TaggedObject *> firstBody = selection01Props->GetTaggedObjectVector
("SelectedObjects");
delete selection01Props;
selection01Props = NULL;
Body *body1(dynamic_cast<Body *>(NXObjectManager::Get(firstBody[0]->Tag())));
bool added1;
added1 = booleanBuilder1->Targets()->Add(body1);
std::vector<TaggedObject *> targets1(1);
targets1[0] = body1;
booleanRegionSelect1->AssignTargets(targets1);
ScCollector *scCollector2;
scCollector2 = workPart->ScCollectors()->CreateCollector();
//获取UI选择的第二个体
PropertyList* selection02Props = selection02->GetProperties();
std::vector<NXOpen::TaggedObject *> secondBody = selection02Props->GetTaggedObjectVector
("SelectedObjects");
delete selection02Props;
selection02Props = NULL;
std::vector<Body *> bodies2(1);
Body *body2(dynamic_cast<Body *>(NXObjectManager::Get(secondBody[0]->Tag())));
bodies2[0] = body2;
BodyDumbRule *bodyDumbRule1;
bodyDumbRule1 = workPart->ScRuleFactory()->CreateRuleBodyDumb(bodies2);
std::vector<SelectionIntentRule *> rules1(1);
rules1[0] = bodyDumbRule1;
scCollector2->ReplaceRules(rules1, false);
booleanBuilder1->SetToolBodyCollector(scCollector2);
std::vector<TaggedObject *> targets2(1);
targets2[0] = body1;
booleanRegionSelect1->AssignTargets(targets2);
NXObject *nXObject1;
nXObject1 = booleanBuilder1->Commit();
booleanBuilder1->Destroy(); //释放