void DZWEIZHI::CreaExtrudeBuilder()//创建拉伸UFUN+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());
//获取选择对象TAG
PropertyList *blockJichengPros = bodySelect0->GetProperties();
std::vector<NXOpen::TaggedObject*> theblockxuanzhe = blockJichengPros->GetTaggedObjectVector("SelectedObjects");
delete blockJichengPros;
blockJichengPros = NULL;
//获取切换开关的值
PropertyList *blocktoggle01Pros = toggle01->GetProperties();
int theblocktoggle01 = blocktoggle01Pros->GetLogical("Value");
delete blocktoggle01Pros;
blocktoggle01Pros = NULL;
UF_initialize();
for (size_t i = 0; i < theblockxuanzhe.size(); i++)
{
tag_t bodyTAG = theblockxuanzhe[i]->Tag();
//tag_t PartTAG = NULL_TAG;
if (UF_ASSEM_is_occurrence(bodyTAG))//判断是否为部件事例标识(occurrence)
{
continue;
}
else
{
UF_ATTR_value_t value;
int title_type;
string strNUMBER, strSS;
UF_ATTR_find_attribute(bodyTAG, UF_ATTR_any, "YX_NUMBER", &title_type);//查找属性
if (title_type != 0)
{
UF_ATTR_read_value(bodyTAG, "YX_NUMBER", UF_ATTR_any, &value);//读取属性
strNUMBER = value.value.string;
}
else
{
break;
}
UF_ATTR_find_attribute(bodyTAG, UF_ATTR_any, "YX_SS", &title_type);//查找属性
if (title_type != 0)
{
UF_ATTR_read_value(bodyTAG, "YX_SS", UF_ATTR_any, &value);//读取属性
strSS = value.value.string;
}
std::vector<std::string> vecSTR;
SplitString(strSS, vecSTR, ",");//调用自定义的SplitString函数对字符串进行分割
double wcsX;
sscanf(vecSTR[4].c_str(), "%lf", &wcsX);
double wcsY;
sscanf(vecSTR[5].c_str(), "%lf", &wcsY);
double wcsZ;
sscanf(vecSTR[6].c_str(), "%lf", &wcsZ);
double note_origin[3];
note_origin[0] = wcsX;
note_origin[1] = wcsY;
note_origin[2] = wcsZ;
CreaTxt(strNUMBER, note_origin);//创建TXT文字
//创建拉伸
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(bodyTAG)));
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());
}
}