NXOpen 简单干涉体改色改透明度和放置图层

//用户头文件
#include <NXOpen/BasePart.hxx>
#include <NXOpen/Body.hxx>
#include <NXOpen/BodyCollection.hxx>
#include <NXOpen/Builder.hxx>
#include <NXOpen/GeometricAnalysis_AnalysisManager.hxx>
#include <NXOpen/GeometricAnalysis_SimpleInterference.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/NXObjectManager.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/TaggedObject.hxx>
#include <NXOpen/TaggedObjectCollection.hxx>
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/DisplayManager.hxx>
#include <NXOpen/DisplayModification.hxx>
#include <NXOpen/DisplayableObject.hxx>
#include <uf_ui.h>
#include <uf.h>

//设置过虑(注释处改动即可使用)
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);

//用户代码
Part *workPart = theSession->Parts()->Work();
Part *displayPart = theSession->Parts()->Display();

//获取UI选择的第一个体
PropertyList* selection01Props = selection01->GetProperties();
std::vector<NXOpen::TaggedObject *> firstBody = selection01Props->GetTaggedObjectVector("SelectedObjects");
delete selection01Props;
selection01Props = NULL;

//获取UI选择的第二个体
PropertyList* selection02Props = selection02->GetProperties();
std::vector<NXOpen::TaggedObject *> secondBody = selection02Props->GetTaggedObjectVector("SelectedObjects");
delete selection02Props;
selection02Props = NULL;

//简单干涉
GeometricAnalysis::SimpleInterference *simpleInterference1;
simpleInterference1 = workPart->AnalysisManager()->CreateSimpleInterferenceObject();

simpleInterference1->SetInterferenceType(GeometricAnalysis::SimpleInterference::InterferenceMethodInterferenceSolid);

Body *body1(dynamic_cast<Body *>(NXObjectManager::Get(firstBody[0]->Tag())));
simpleInterference1->FirstBody()->SetValue(body1);

Body *body2(dynamic_cast<Body *>(NXObjectManager::Get(secondBody[0]->Tag())));
simpleInterference1->SecondBody()->SetValue(body2);

GeometricAnalysis::SimpleInterference::Result result1;
result1 = simpleInterference1->PerformCheck();

NXObject *nXObject1;
nXObject1 = simpleInterference1->Commit();

vector<NXOpen::NXObject *> interferenceObj;
interferenceObj = simpleInterference1->GetInterferenceResults();

simpleInterference1->Destroy();

//获取颜色值控件
PropertyList *blockColorProps = colorPicker0->GetProperties();
std::vector<int> color = blockColorProps->GetIntegerVector("Value");
delete blockColorProps;
blockColorProps = NULL;
//获取图层实数型的值
PropertyList *integer0LayerProps = integer0Layer->GetProperties();
int integer0LayerValue = integer0LayerProps->GetInteger("Value");
delete integer0LayerProps;
integer0LayerProps = NULL;

//得到的干涉体改色和放置图层
DisplayModification *displayModification1;
displayModification1 = theSession->DisplayManager()->NewDisplayModification();

displayModification1->SetApplyToAllFaces(false);

displayModification1->SetApplyToOwningParts(false);

displayModification1->SetNewTranslucency(70); //设置透明度
displayModification1->SetNewLayer(integer0LayerValue);//设置图层

displayModification1->SetNewColor(color[0]);//得到的色值是int类型,存在vector数组里,使用时取数组里的第一个值[0]

displayModification1->SetNewWidth(DisplayableObject::ObjectWidthOne);

std::vector<DisplayableObject *> objects1(1);
Body *body3(dynamic_cast<Body *>(NXObjectManager::Get(interferenceObj[0]->Tag())));
objects1[0] = body3;
displayModification1->Apply(objects1);

 delete displayModification1;

怡宁塑胶模具设计
原文地址:https://www.cnblogs.com/hqsalanhuang/p/14179117.html