/*曲线拉伸出片体*/
bool extrudeSheet(std::vector<tag_t> vCurve, double dir[3], double LimitStart, double LimitEnd, tag_t* tFeature, std::vector<tag_t>& Featurebodys, int get_type)//close list ;1,feature ;2,body
{
UF_UNDO_mark_id_t mark_id;
try
{
UF_CALL(UF_UNDO_set_mark(UF_UNDO_visible, NULL, &mark_id));
char czLimitStart[256];
char czLimitEnd[256];
tag_t curve_tag;
int type;
int subtype;
Session* theSession = Session::GetSession();
Part* workPart(theSession->Parts()->Work());
Features::Feature* nullFeatures_Feature(NULL);
Features::ExtrudeBuilder* extrudeBuilder1;
extrudeBuilder1 = workPart->Features()->CreateExtrudeBuilder(nullFeatures_Feature);
Section* section1;
section1 = workPart->Sections()->CreateSection(0.00095, 0.001, 0.05);
extrudeBuilder1->SetSection(section1);
extrudeBuilder1->AllowSelfIntersectingSection(true);
//extrudeBuilder1->SetDistanceTolerance(0.001);
//extrudeBuilder1->SetDistanceTolerance(0.05);
//extrudeBuilder1->SetDistanceTolerance(0.1);
extrudeBuilder1->SetDistanceTolerance(0.0254);
extrudeBuilder1->BooleanOperation()->SetType(GeometricUtilities::BooleanOperation::BooleanTypeCreate);
#pragma region Limits
sprintf(czLimitStart, "%f", LimitStart);
extrudeBuilder1->Limits()->StartExtend()->Value()->SetRightHandSide(czLimitStart);
sprintf(czLimitEnd, "%f", LimitEnd);
extrudeBuilder1->Limits()->EndExtend()->Value()->SetRightHandSide(czLimitEnd);
#pragma endregion
#pragma region SetTargetBodies
extrudeBuilder1->FeatureOptions()->SetBodyType(GeometricUtilities::FeatureOptions::BodyStyleSheet);
extrudeBuilder1->BooleanOperation()->SetType(GeometricUtilities::BooleanOperation::BooleanTypeCreate);
std::vector<Body*> targetBodies1(1);
Body* nullBody(NULL);
targetBodies1[0] = nullBody;
extrudeBuilder1->BooleanOperation()->SetTargetBodies(targetBodies1);
#pragma endregion
/*extrudeBuilder1->Draft()->FrontDraftAngle()->SetRightHandSide("-7");
extrudeBuilder1->Draft()->BackDraftAngle()->SetRightHandSide("2");
extrudeBuilder1->Offset()->StartOffset()->SetRightHandSide("0");
extrudeBuilder1->Offset()->EndOffset()->SetRightHandSide("3");*/
GeometricUtilities::SmartVolumeProfileBuilder* smartVolumeProfileBuilder1;
smartVolumeProfileBuilder1 = extrudeBuilder1->SmartVolumeProfile();
smartVolumeProfileBuilder1->SetOpenProfileSmartVolumeOption(false);
//smartVolumeProfileBuilder1->SetCloseProfileRule(GeometricUtilities::SmartVolumeProfileBuilder::CloseProfileRuleTypeFci);
#pragma region SetDirection
Point3d origin1(0.0, 0.0, 0.0);
Vector3d vector1(dir[0], dir[1], dir[2]);
Direction* direction1;
direction1 = workPart->Directions()->CreateDirection(origin1, vector1, SmartObject::UpdateOptionWithinModeling);
extrudeBuilder1->SetDirection(direction1);
#pragma endregion
//section1->SetDistanceTolerance(0.001);
//section1->SetChainingTolerance(0.00095);
//section1->SetDistanceTolerance(0.05);
//section1->SetChainingTolerance(0.05-0.005);
section1->SetDistanceTolerance(0.0254);
section1->SetChainingTolerance(0.02413);
section1->SetAllowedEntityTypes(Section::AllowTypesOnlyCurves);
#pragma region AddToSection
std::vector<IBaseCurve*> curves1;
for (int i = 0; i < vCurve.size(); i++)
{
curve_tag = vCurve[i];
UF_CALL(UF_OBJ_ask_type_and_subtype(curve_tag, &type, &subtype));
if (UF_line_type == type)
curves1.push_back((NXOpen::Line*)NXOpen::NXObjectManager::Get(curve_tag));
else if (UF_circle_type == type)
curves1.push_back((NXOpen::Arc*)NXOpen::NXObjectManager::Get(curve_tag));
else if (UF_spline_type == type)
curves1.push_back((NXOpen::Spline*)NXOpen::NXObjectManager::Get(curve_tag));
else if (UF_conic_type == type && UF_conic_ellipse_subtype == subtype)
curves1.push_back((NXOpen::Ellipse*)NXOpen::NXObjectManager::Get(curve_tag));
else if (UF_conic_type == type && UF_conic_parabola_subtype == subtype)
curves1.push_back((NXOpen::Parabola*)NXOpen::NXObjectManager::Get(curve_tag));
else if (UF_conic_type == type && UF_conic_hyperbola_subtype == subtype)
curves1.push_back((NXOpen::Hyperbola*)NXOpen::NXObjectManager::Get(curve_tag));
}
CurveDumbRule* curveDumbRule1;
curveDumbRule1 = workPart->ScRuleFactory()->CreateRuleBaseCurveDumb(curves1);
section1->AllowSelfIntersection(true);
std::vector<SelectionIntentRule*> rules1;
rules1.push_back(curveDumbRule1);
NXObject* nullNXObject(NULL);
Point3d helpPoint1(0.0, 0.0, 0.0);
section1->AddToSection(rules1, nullNXObject, nullNXObject, nullNXObject, helpPoint1, Section::ModeCreate, false);
#pragma endregion
#pragma region CommitFeature
extrudeBuilder1->SetParentFeatureInternal(false);
Features::Feature* feature1;
feature1 = extrudeBuilder1->CommitFeature();
if (NULL == feature1)
{
uc1601("不能 创建拉伸", 0);
return 0;
}
*tFeature = NULL_TAG;
if (1 == get_type)
* tFeature = feature1->Tag();
else
{
UF_MODL_ask_feat_body(feature1->Tag(), tFeature);//2的时候,tFeature为第一个拉伸体,Featurebodys存着所有拉伸体
std::vector<Body*> test = dynamic_cast<Features::BodyFeature*>(feature1)->GetBodies();
size_t iCount(test.size());
Featurebodys.clear();
for (size_t i(0); i < iCount; ++i)
{
Featurebodys.push_back(ask_obj_tag(test[i]));
}
}
extrudeBuilder1->Destroy();
if (NULL_TAG == *tFeature)
{
uc1601("不能 创建拉伸", 0);
return 0;
}
#pragma endregion
return 1;
}
catch (exception& ex)
{
UF_CALL(UF_UNDO_undo_to_mark(mark_id, NULL));
return 0;
}
}
【UG\NX二次开发】曲线拉伸出片体
于 2023-11-09 15:38:15 首次发布