NXOpen-创建固定约束

void CreateFixedConstraint(tag_t component)
{
	if (NULL_TAG == component)
	{
		return;
	}

	NXOpen::Session *theSession = NXOpen::Session::GetSession();
	NXOpen::Part *workPart(theSession->Parts()->Work());

	NXOpen::Positioning::ComponentPositioner *componentPositioner1 = workPart->ComponentAssembly()->Positioner();
	componentPositioner1->ClearNetwork();
	componentPositioner1->SetPrimaryArrangement(NULL);
	componentPositioner1->BeginAssemblyConstraints();

	NXOpen::Positioning::Network *network1 = componentPositioner1->EstablishNetwork();
	NXOpen::Positioning::ComponentNetwork *componentNetwork1(dynamic_cast<NXOpen::Positioning::ComponentNetwork *>(network1));
	componentNetwork1->SetMoveObjectsState(true);
	componentNetwork1->SetDisplayComponent(NULL);
	componentNetwork1->SetNetworkArrangementsMode(NXOpen::Positioning::ComponentNetwork::ArrangementsModeExisting);

	NXOpen::Assemblies::Component *component1(dynamic_cast<NXOpen::Assemblies::Component *>(UDS::ToNXObj(component)));
	NXOpen::Positioning::Constraint *constraint1 = componentPositioner1->CreateConstraint(true);
	NXOpen::Positioning::ComponentConstraint *componentConstraint1(dynamic_cast<NXOpen::Positioning::ComponentConstraint *>(constraint1));
	componentConstraint1->SetConstraintType(NXOpen::Positioning::Constraint::TypeFix);

	NXOpen::Positioning::ConstraintReference *constraintReference1 = componentConstraint1->CreateConstraintReference(component1, component1, false, false, false);

	componentNetwork1->Solve();
	componentPositioner1->ClearNetwork();
	theSession->UpdateManager()->AddToDeleteList(componentNetwork1);
	componentPositioner1->DeleteNonPersistentConstraints();
	componentPositioner1->EndAssemblyConstraints();
}
上一篇:用两个函数模板来实现整型、实型、字符型的排序和输出


下一篇:前端学习心得(20211202)