|
小新
发表于 2014-5-8 15:55:39
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 小新 于 2014-5-8 16:10 编辑 2 E/ N& I' E \8 Y! L
$ e2 C3 H/ y) }
录制装配过程的JA,经过对录制的代码进行简化删减后,如下,经编译后能够实现自动化装配。- Session *theSession = Session::GetSession();
6 k& F( K" g0 H5 Z. c! m# p - Part *workPart(theSession->Parts()->Work());( P4 @: T( W% B' {
- Part *displayPart(theSession->Parts()->Display());
, d @4 d1 q7 v2 A( t% `+ J6 v - ' m& `7 c, A0 a4 e( a& {! e. K
- BasePart *basePart1;7 d# b2 }8 h. y
- PartLoadStatus *partLoadStatus1;6 p+ z/ y7 L, i
- basePart1 = theSession->Parts()->OpenBase("D:\\sy\\model4.prt", &partLoadStatus1);: F3 z& B7 h$ A3 [) o6 P
- delete partLoadStatus1;
/ Q9 o, x* ]% J* ^/ S0 S -
6 g( s, e" \3 ~( R! E0 p l7 G1 R. m - Point3d basePoint1(0.0, 0.0, 0.0);
' S1 T7 p/ r. @6 x: A3 C - Matrix3x3 orientation1;9 K W0 F, u1 Z" A% m R5 S& ^
- orientation1.Xx = 1.0; orientation1.Xy = 0.0; orientation1.Xz = 0.0;
2 n) B# ]: W7 y: M; m9 b0 _ - orientation1.Yx = 0.0; orientation1.Yy = 1.0; orientation1.Yz = 0.0;
! e% P% Z, b9 @ - orientation1.Zx = 0.0; orientation1.Zy = 0.0; orientation1.Zz = 1.0;
3 e5 ~; X* v3 Y+ Z! [$ n C - PartLoadStatus *partLoadStatus2;
, x- d3 E! C$ {5 n3 n - Assemblies::Component *component1;
! O. ? Y B6 d: S/ G. x7 x - component1 = workPart->ComponentAssembly()->AddComponent("D:\\sy\\model4.prt", "MODEL", "MODEL4", basePoint1, orientation1, -1, &partLoadStatus2, true);//添加组件
9 W0 z3 N6 c/ B u, g( Q6 _. r: I6 ` - delete partLoadStatus2; 3 d0 z; `5 _4 h. h/ s J
- 6 b) Y4 x/ }" [. b# z4 e5 G$ m7 A
- BasePart *basePart2;
# B1 E: f! }' q- ?. I3 \% U - PartLoadStatus *partLoadStatus3;0 k0 n& Q8 y, s# n. o9 W5 O# |
- basePart2 = theSession->Parts()->OpenBase("D:\\sy\\model5.prt", &partLoadStatus3); $ \: B' ~9 d7 q
- delete partLoadStatus3; 5 L! X: k" v# }$ R* m5 w/ N
- ! F$ z: s% m) ]- z" j. P
- Point3d basePoint2(0.0, 0.0, 0.0);7 D& u* I% |! y5 O: ]: ~
- Matrix3x3 orientation2;
& ]4 c6 `: @" G+ k - orientation2.Xx = 1.0; orientation2.Xy = 0.0; orientation2.Xz = 0.0;! i6 k4 m7 b% m6 m9 z
- orientation2.Yx = 0.0; orientation2.Yy = 1.0; orientation2.Yz = 0.0;) f; y0 J. N7 ?; m( u' h! e Y
- orientation2.Zx = 0.0; orientation2.Zy = 0.0; orientation2.Zz = 1.0;1 P. A- y. @0 ~. s4 l! x! V
- PartLoadStatus *partLoadStatus4;" d' ?, T p T6 s& Q0 M* Q; }5 E* M
- Assemblies::Component *component2;+ |- C7 `" ~# N( s4 B
- component2 = workPart->ComponentAssembly()->AddComponent("D:\\sy\\model5.prt", "MODEL", "MODEL5", basePoint2, orientation2, -1, &partLoadStatus4, true);//添加组件
3 S* h8 v& x4 H2 `% r1 g - delete partLoadStatus4; : U3 N& V! [" D
- ( W7 }: y* E8 V% t. a* W
- Positioning::ComponentPositioner *componentPositioner1;9 L5 L$ }" d- Q& I, ~5 {
- componentPositioner1 = workPart->ComponentAssembly()->Positioner(); ' y! v, E, I8 D, w0 v6 |! S* `# J
- componentPositioner1->BeginAssemblyConstraints(); 9 V5 b; B) Z, l6 o" J% d; r
- 0 F$ a, V* `, E7 i! [
- Positioning::Network *network1;5 [7 I$ |: ]: a2 b
- network1 = componentPositioner1->EstablishNetwork(); ( M: ]% o8 D. I( x8 H9 y0 I
- Positioning::ComponentNetwork *componentNetwork1(dynamic_cast<Positioning::ComponentNetwork *>(network1));( S$ _9 ~+ l( [2 o" a+ ~
- componentNetwork1->SetMoveObjectsState(true); ' ?4 J) h6 t! [! I: r* _9 k% g2 B
- , e" j N. l4 n% `# q, `6 d
- Positioning::Constraint *constraint1;& b) B g2 V: ~" w
- constraint1 = componentPositioner1->CreateConstraint(true);
& E) v+ _3 }+ r/ n5 K3 q - , G+ A, Q) A' e! Z* L/ D
- Positioning::ComponenTConstraint *componentConstraint1(dynamic_cast<Positioning::ComponentConstraint *>(constraint1));
- h& @) s5 P; K* ` - componentConstraint1->SetConstraintAlignment(Positioning::Constraint::AlignmentContraAlign); 0 D! C" h3 m) S% ?( {
- componentConstraint1->SetConstraintType(Positioning::Constraint::TypeTouch);& A0 r. X2 @7 Y
- ' p7 s4 u0 ]. Q3 E/ X- f
- Face *face1(dynamic_cast<Face *>(component2->FindObject("PROTO#.Features|BLOCK(1)|FACE 6 {(500,25,25) BLOCK(1)}"))); 9 C! q {) l/ c" g
- Positioning::ConstraintReference *constraintReference1;
复制代码 但是出现了一个问题,在上述代码中,进行装配的面是通过FindObject来找到的,不是我想要的那个面,而且FindObject函数参数是一个JA标识符,我无法给某个面定义JA标示符。如果我在建立模型时,我给某个面命名为FACE1。那么我如何找到我想要的面FACE1,然后用于代码
. T6 k. G6 P4 F/ \- N6 f% D( s- constraintReference1 = componentConstraint1->CreateConstraintReference(component2, face1, false, false, false);
复制代码 其中上述代码中第二参数类型是NXObject *,也无法通过Ufun函数的UF_OBJ_cycle_by_name找到,因为该函数找到是FACE1面的tag,返回的类型不是NXObject *。4 e! t% z1 }) ~) J5 \+ g6 {
问题:
& d5 a5 c, V2 ~$ M* d0 v1)C++中是否有某个方法通过某个对象的tag返回其NXObject *类型
I* P- \* U8 `, I; v2)C++是否有某个类中的方法可以找到occurrence中的面(CreateConstraintReference需要的是occurrence的对象),而且返回的是NXObject *类型对象,可以直接用于CreateConstraintReference()方法。
7 p9 V6 u' L6 ?) O# S/ T
* e( E( l0 ] O3 f% ^* H |
|