/*录制:创建单条曲线长度(输入边或样条曲线,以及起始端点)*/
bool CreateCurveLength(tag_t objTag, double StartPoint[3], double StartDist, double EndDist, tag_t& CurveLengthFeatureTag)
{
try
{
Session* theSession = Session::GetSession();
Part* workPart(theSession->Parts()->Work());
Part* displayPart(theSession->Parts()->Display());
Section* section1;
section1 = workPart->Sections()->CreateSection(0.02413, 0.0254, 0.05);
Features::Feature* nullFeatures_Feature(NULL);
if (!workPart->Preferences()->Modeling()->GetHistoryMode())
{
throw NXException::Create("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode.");
}
Features::CurveLengthBuilder* curveLengthBuilder1;
curveLengthBuilder1 = workPart->Features()->CreateCurvelengthBuilder(nullFeatures_Feature);
curveLengthBuilder1->SetSection(section1);
curveLengthBuilder1->SetDistanceTolerance(0.0254);
curveLengthBuilder1->CurveOptions()->SetAssociative(false);
curveLengthBuilder1->CurveOptions()->SetInputCurveOption(GeometricUtilities::CurveOptions::InputCurveReplace);
curveLengthBuilder1->CurvelengthData()->SetExtensionMethod(GeometricUtilities::ExtensionMethodIncremental);
curveLengthBuilder1->CurvelengthData()->SetExtensionSide(GeometricUtilities::ExtensionSideStartEnd);
curveLengthBuilder1->CurvelengthData()->SetExtensionDirection(GeometricUtilities::ExtensionDirectionNatural);
section1->SetDistanceTolerance(0.0254);
section1->SetChainingTolerance(0.02413);
char StartDistChar[256];
char EndDistChar[256];
sprintf(StartDistChar, "%f", StartDist);
sprintf(EndDistChar, "%f", EndDist);
curveLengthBuilder1->CurvelengthData()->SetStartDistance(StartDistChar);//开始位置
curveLengthBuilder1->CurvelengthData()->SetEndDistance(EndDistChar);//结束位置
section1->SetAllowedEntityTypes(Section::AllowTypesOnlyCurves);
SelectionIntentRule* tmp_Rule;
NXObject* seed;
int type;
int subtype;
UF_OBJ_ask_type_and_subtype(objTag, &type, &subtype);
char msg11[256];
sprintf(msg11, "%d,%d", type, subtype);
//uc1601(msg11, 1);
if (UF_solid_type == type && UF_solid_edge_subtype == subtype)
{
std::vector<Edge*> edges1(1);
Edge* edge1(dynamic_cast<Edge*>(NXObjectManager::Get(objTag)));
edges1[0] = edge1;
EdgeDumbRule* edgeDumbRule1;
edgeDumbRule1 = workPart->ScRuleFactory()->CreateRuleEdgeDumb(edges1);
tmp_Rule = edgeDumbRule1;
seed = edge1;
}
else if (UF_line_type == type)
{
std::vector<IBaseCurve*> curves1(1);
NXOpen::Line* line1(dynamic_cast<NXOpen::Line*>(NXObjectManager::Get(objTag)));
curves1[0] = line1;
CurveDumbRule* curveDumbRule1;
curveDumbRule1 = workPart->ScRuleFactory()->CreateRuleBaseCurveDumb(curves1);
tmp_Rule = curveDumbRule1;
seed = line1;
}
else if (UF_circle_type == type)
{
std::vector<IBaseCurve*> curves1(1);
NXOpen::Arc* arc1(dynamic_cast<NXOpen::Arc*>(NXObjectManager::Get(objTag)));
curves1[0] = arc1;
CurveDumbRule* curveDumbRule1;
curveDumbRule1 = workPart->ScRuleFactory()->CreateRuleBaseCurveDumb(curves1);
tmp_Rule = curveDumbRule1;
seed = arc1;
}
else if (UF_spline_type == type && UF_spline_subtype == subtype)
{
std::vector<IBaseCurve*> curves1(1);
Spline* spline1(dynamic_cast<Spline*>(NXObjectManager::Get(objTag)));
curves1[0] = spline1;
CurveDumbRule* curveDumbRule1;
curveDumbRule1 = workPart->ScRuleFactory()->CreateRuleBaseCurveDumb(curves1);
tmp_Rule = curveDumbRule1;
seed = spline1;
}
else if (UF_conic_type == type && UF_conic_ellipse_subtype == subtype)
{
std::vector<IBaseCurve*> curves1(1);
NXOpen::Ellipse* ellipse1(dynamic_cast<NXOpen::Ellipse*>(NXObjectManager::Get(objTag)));
curves1[0] = ellipse1;
CurveDumbRule* curveDumbRule1;
curveDumbRule1 = workPart->ScRuleFactory()->CreateRuleBaseCurveDumb(curves1);
tmp_Rule = curveDumbRule1;
seed = ellipse1;
}
else if (UF_conic_type == type && UF_conic_parabola_subtype == subtype)
{
std::vector<IBaseCurve*> curves1(1);
NXOpen::Parabola* parabola1(dynamic_cast<NXOpen::Parabola*>(NXObjectManager::Get(objTag)));
curves1[0] = parabola1;
CurveDumbRule* curveDumbRule1;
curveDumbRule1 = workPart->ScRuleFactory()->CreateRuleBaseCurveDumb(curves1);
tmp_Rule = curveDumbRule1;
seed = parabola1;
}
else if (UF_conic_type == type && UF_conic_hyperbola_subtype == subtype)
{
std::vector<IBaseCurve*> curves1(1);
NXOpen::Hyperbola* hyperbola1(dynamic_cast<NXOpen::Hyperbola*>(NXObjectManager::Get(objTag)));
curves1[0] = hyperbola1;
CurveDumbRule* curveDumbRule1;
curveDumbRule1 = workPart->ScRuleFactory()->CreateRuleBaseCurveDumb(curves1);
tmp_Rule = curveDumbRule1;
seed = hyperbola1;
}
section1->AllowSelfIntersection(true);
std::vector<SelectionIntentRule*> rules1(1);
rules1[0] = tmp_Rule;
NXObject* nullNXObject(NULL);
Point3d helpPoint1(StartPoint[0], StartPoint[1], StartPoint[2]);//辅助点
section1->AddToSection(rules1, seed, nullNXObject, nullNXObject, helpPoint1, Section::ModeCreate, false);
NXObject* nXObject1;
nXObject1 = curveLengthBuilder1->Commit();
std::vector<NXObject*> objects1;
objects1 = curveLengthBuilder1->GetCommittedObjects();
if(objects1.size()==1)
CurveLengthFeatureTag = objects1[0]->Tag();
curveLengthBuilder1->Destroy();
}
catch (exception& ex)
{
return 1;
}
return 0;
}
【UG\NX二次开发】NXOpen 曲线长度(可以拿来抽取边上的线)、输入边与曲线等各种类型的适配的方法
于 2023-11-09 15:36:52 首次发布