NXOpenC++装配体约束出现问题
图中接触约束明明已经求解成功,为什么这两个面没有合上呢,而且创建的接触约束和对齐约束双击之后都不能重定义,
如下图。显示添加的引用无效(想想只有可能是选择的接触面不对,但图中接触面看得出来就是我要选择的面),
但具体不知道什么无效,有谁能帮忙解答吗??
能否指明一下,是那两个面要接触对齐呢?? UG自在观 发表于 2016-6-16 10:11
能否指明一下,是那两个面要接触对齐呢??
可以看图一,我选中了接触这个约束,图上面夹着白色圆柱那段的左右两个圆环面。 对齐之后,试一试用同心约束。看一看是否可以 还不行,介意再把图档上传。我看一看 UG自在观 发表于 2016-6-16 16:42
还不行,介意再把图档上传。我看一看
我先把我做的接触约束代码发上来,(整个做装配的代码比较长,不知道这里能不能上传文件,可以的话我就把全部文件代码发给你)我创建的是螺栓螺母装配,全称包括模型都是代码生成的。可以看我之前发的图片,代码中comp1和comp2是我创建的两个组件(comp1中创建两个圆柱体作布尔和,即螺栓部分,comp2中创建两个圆柱体作布尔差,即螺母部分),找接触约束配合面的那部分代码中的bd11_Tag是组件comp1中创建的两个圆柱体做布尔和后获得的实体,bd22_Tag是组件comp2中两个圆柱体作布尔差后获得的体。
//接触约束
NXOpen::Positioning::ComponentPositioner *componentPositioner3;
componentPositioner3 = workPart->ComponentAssembly()->Positioner();
componentPositioner3->ClearNetwork();
NXOpen::Assemblies::Arrangement *arrangement1(dynamic_cast<NXOpen::Assemblies::Arrangement *>(workPart->ComponentAssembly()->Arrangements()->FindObject("Arrangement 1")));
componentPositioner3->SetPrimaryArrangement(arrangement1);
componentPositioner3->BeginAssemblyConstraints();
NXOpen::Positioning::Network *network3;
network3 = componentPositioner3->EstablishNetwork();
NXOpen::Positioning::ComponentNetwork *componentNetwork3(dynamic_cast<NXOpen::Positioning::ComponentNetwork *>(network3));
componentNetwork3->SetMoveObjectsState(true);
NXOpen::Assemblies::Component *nullNXOpen_Assemblies_Component(NULL);
componentNetwork1->SetDisplayComponent(nullNXOpen_Assemblies_Component);
componentNetwork1->SetNetworkArrangementsMode(NXOpen::Positioning::ComponentNetwork::ArrangementsModeExisting);
componentNetwork1->SetMoveObjectsState(true);
componentNetwork1->SetNetworkArrangementsMode(NXOpen::Positioning::ComponentNetwork::ArrangementsModeExisting);
NXOpen::Positioning::Constraint *constraint3;
constraint3 = componentPositioner3->CreateConstraint(true);
NXOpen::Positioning::ComponentConstraint *componentConstraint3(dynamic_cast<NXOpen::Positioning::ComponentConstraint *>(constraint3));
componentConstraint3->SetConstraintAlignment(NXOpen::Positioning::Constraint::AlignmentInferAlign);
componentConstraint3->SetConstraintType(NXOpen::Positioning::Constraint::TypeTouch);
uf_list_p_t face_list1;
tag_tobject_id1 =NULL_TAG;
UF_MODL_create_list(&face_list1); //初始化列表
UF_MODL_ask_body_faces (bd11_Tag, &face_list1);//获得实体上所有表面
UF_MODL_ask_list_item(face_list1,0,&object_id1);
UF_OBJ_set_color(object_id1,3);
Face *face1;
face1=dynamic_cast<NXOpen::Face *>(NXObjectManager::Get(object_id1));
uf_list_p_t face_list2;
tag_tobject_id2 =NULL_TAG;
UF_MODL_create_list(&face_list2); //初始化列表
UF_MODL_ask_body_faces (bd22_Tag, &face_list2);//获得实体上所有表面
UF_MODL_ask_list_item(face_list2,1,&object_id2);
UF_OBJ_set_color(object_id2,3);
Face *face2;
face2=dynamic_cast<NXOpen::Face *>(NXObjectManager::Get(object_id2));
NXOpen::Positioning::ConstraintReference *constraintReference1;
constraintReference3 = componentConstraint3->CreateConstraintReference(comp1, face1, false, false, false);
NXOpen::Positioning::ConstraintReference *constraintReference2;
constraintReference2 = componentConstraint3->CreateConstraintReference(comp2, face2, false, false, false);
constraintReference2->SetFixHint(true);
componentNetwork1->Solve();
componentPositioner3->ClearNetwork();
componentPositioner3->DeleteNonPersistentConstraints();
NXOpen::Assemblies::Arrangement *nullNXOpen_Assemblies_Arrangement(NULL);
componentPositioner3->SetPrimaryArrangement(nullNXOpen_Assemblies_Arrangement);
componentPositioner3->EndAssemblyConstraints();
UG自在观 发表于 2016-6-16 16:42
对齐之后,试一试用同心约束。看一看是否可以
我创建了3个约束,先对comp1固定,然后让两个圆柱面通过轴对齐约束,最后是两个圆环面接触约束
页:
[1]