如何查找一个部件对应的occurrence的面
本帖最后由 小新 于 2014-5-8 16:10 编辑录制装配过程的JA,经过对录制的代码进行简化删减后,如下,经编译后能够实现自动化装配。Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());
BasePart *basePart1;
PartLoadStatus *partLoadStatus1;
basePart1 = theSession->Parts()->OpenBase("D:\\sy\\model4.prt", &partLoadStatus1);
delete partLoadStatus1;
Point3d basePoint1(0.0, 0.0, 0.0);
Matrix3x3 orientation1;
orientation1.Xx = 1.0; orientation1.Xy = 0.0; orientation1.Xz = 0.0;
orientation1.Yx = 0.0; orientation1.Yy = 1.0; orientation1.Yz = 0.0;
orientation1.Zx = 0.0; orientation1.Zy = 0.0; orientation1.Zz = 1.0;
PartLoadStatus *partLoadStatus2;
Assemblies::Component *component1;
component1 = workPart->ComponentAssembly()->AddComponent("D:\\sy\\model4.prt", "MODEL", "MODEL4", basePoint1, orientation1, -1, &partLoadStatus2, true);//添加组件
delete partLoadStatus2;
BasePart *basePart2;
PartLoadStatus *partLoadStatus3;
basePart2 = theSession->Parts()->OpenBase("D:\\sy\\model5.prt", &partLoadStatus3);
delete partLoadStatus3;
Point3d basePoint2(0.0, 0.0, 0.0);
Matrix3x3 orientation2;
orientation2.Xx = 1.0; orientation2.Xy = 0.0; orientation2.Xz = 0.0;
orientation2.Yx = 0.0; orientation2.Yy = 1.0; orientation2.Yz = 0.0;
orientation2.Zx = 0.0; orientation2.Zy = 0.0; orientation2.Zz = 1.0;
PartLoadStatus *partLoadStatus4;
Assemblies::Component *component2;
component2 = workPart->ComponentAssembly()->AddComponent("D:\\sy\\model5.prt", "MODEL", "MODEL5", basePoint2, orientation2, -1, &partLoadStatus4, true);//添加组件
delete partLoadStatus4;
Positioning::ComponentPositioner *componentPositioner1;
componentPositioner1 = workPart->ComponentAssembly()->Positioner();
componentPositioner1->BeginAssemblyConstraints();
Positioning::Network *network1;
network1 = componentPositioner1->EstablishNetwork();
Positioning::ComponentNetwork *componentNetwork1(dynamic_cast<Positioning::ComponentNetwork *>(network1));
componentNetwork1->SetMoveObjectsState(true);
Positioning::Constraint *constraint1;
constraint1 = componentPositioner1->CreateConstraint(true);
Positioning::ComponentConstraint *componentConstraint1(dynamic_cast<Positioning::ComponentConstraint *>(constraint1));
componentConstraint1->SetConstraintAlignment(Positioning::Constraint::AlignmentContraAlign);
componentConstraint1->SetConstraintType(Positioning::Constraint::TypeTouch);
Face *face1(dynamic_cast<Face *>(component2->FindObject("PROTO#.Features|BLOCK(1)|FACE 6 {(500,25,25) BLOCK(1)}")));
Positioning::ConstraintReference *constraintReference1;但是出现了一个问题,在上述代码中,进行装配的面是通过FindObject来找到的,不是我想要的那个面,而且FindObject函数参数是一个JA标识符,我无法给某个面定义JA标示符。如果我在建立模型时,我给某个面命名为FACE1。那么我如何找到我想要的面FACE1,然后用于代码
constraintReference1 = componentConstraint1->CreateConstraintReference(component2, face1, false, false, false);其中上述代码中第二参数类型是NXObject *,也无法通过Ufun函数的UF_OBJ_cycle_by_name找到,因为该函数找到是FACE1面的tag,返回的类型不是NXObject *。
问题:
1)C++中是否有某个方法通过某个对象的tag返回其NXObject *类型
2)C++是否有某个类中的方法可以找到occurrence中的面(CreateConstraintReference需要的是occurrence的对象),而且返回的是NXObject *类型对象,可以直接用于CreateConstraintReference()方法。
tag 可以通过 NXObjectManager 返回 NXobject
页:
[1]