void DZWEIZHI::CreaExtrude(string str, double note_origin[3], tag_t Obj)//创建拉伸nxopen方式
{
try
{
//---- Enter your callback code here -----
NXOpen::Session *theSession = NXOpen::Session::GetSession();
NXOpen::Part *workPart(theSession->Parts()->Work());
NXOpen::Part *displayPart(theSession->Parts()->Display());
//获取切换开关的值
PropertyList *blocktoggle01Pros = toggle01->GetProperties();
int theblocktoggle01 = blocktoggle01Pros->GetLogical("Value");
delete blocktoggle01Pros;
blocktoggle01Pros = NULL;
UF_initialize();
//CreaTxt(str, note_origin);//优化后就不用写在这里了
//创建拉伸
Features::Feature *nullFeatures_Feature(NULL);
Features::ExtrudeBuilder *extrudeBuilder1;
extrudeBuilder1 = workPart->Features()->CreateExtrudeBuilder(nullFeatures_Feature);
extrudeBuilder1->SetDistanceTolerance(0.001);//设置公差
//设置截面
Section *section1;
section1 = workPart->Sections()->CreateSection();
extrudeBuilder1->SetSection(section1);
NXOpen::Features::Feature *text1 = dynamic_cast<Features::Text *>(vecTAGtxt[0]);//选择拉伸对象
std::vector<Features::Feature *> Rulefeatures(1);
Rulefeatures[0] = text1;
CurveFeatureRule *curveFeatureRule1;
curveFeatureRule1 = workPart->ScRuleFactory()->CreateRuleCurveFeature(Rulefeatures);//建立选择意图
std::vector<SelectionIntentRule *> rules1(1);
rules1[0] = curveFeatureRule1;
NXObject *nullNXObject(NULL);
Point3d helpPoint1(0.0, 0.0, 0.0);
section1->AddToSection(rules1, nullNXObject, nullNXObject, nullNXObject, helpPoint1, Section::ModeCreate, false);//按意图进行选择
//Point3d OriginalWcsOrigin;//WCS 原点
//OriginalWcsOrigin = workPart->WCS()->Origin();//获得WCS原点
Point3d theOrigin = { note_origin[0],note_origin[1],note_origin[2] };
NXOpen::Vector3d vector1(0.0, 0.0, 1.0);//定义方向
//设置拉伸方向
Direction *direction1;
direction1 = workPart->Directions()->CreateDirection(theOrigin, vector1, SmartObject::UpdateOptionWithinModeling);
//ExtrudeDepth = atof(theDepth.GetLocaleText());//深度转Double型
extrudeBuilder1->Limits()->StartExtend()->Value()->SetValue(-0.2);//设置拉伸起始点
extrudeBuilder1->Limits()->EndExtend()->Value()->SetValue(0.2);//设置拉伸起终点
extrudeBuilder1->SetDirection(direction1);//设置拉伸方向
if (theblocktoggle01 == 1)
{
extrudeBuilder1->BooleanOperation()->SetType(NXOpen::GeometricUtilities::BooleanOperation::BooleanTypeSubtract);//设置布尔运算
std::vector<NXOpen::Body *> targetBodies3(1);
//NXOpen::Body *body1(dynamic_cast<NXOpen::Body *>(workPart->Bodies()->FindObject("UNPARAMETERIZED_FEATURE(33)")));
NXOpen::Body *body1(dynamic_cast<NXOpen::Body *>(NXOpen::NXObjectManager::Get(Obj)));//设置布尔运算的工具体
targetBodies3[0] = body1;
extrudeBuilder1->BooleanOperation()->SetTargetBodies(targetBodies3);//设置布尔运算
}
NXOpen::Features::Feature *feature1;
feature1 = extrudeBuilder1->CommitFeature();
extrudeBuilder1->Destroy();
UF_terminate();
}
catch (exception& ex)
{
//---- Enter your exception handling code here -----
DZWEIZHI::theUI->NXMessageBox()->Show("创建拉伸", NXOpen::NXMessageBox::DialogTypeError, ex.what());
}
}