【UG\NX二次开发】NXOpen 曲线长度(可以拿来抽取边上的线)、输入边与曲线等各种类型的适配的方法

/*录制:创建单条曲线长度(输入边或样条曲线,以及起始端点)*/
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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

社恐猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值