PLM之家PLMHome-工业软件践行者

[已解决] 如何查找一个部件对应的occurrence的面

[复制链接]

2014-5-9 10:26:29 3534 1

小新 发表于 2014-5-8 15:55:39 |阅读模式

小新 楼主

2014-5-8 15:55:39

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 小新 于 2014-5-8 16:10 编辑 + P1 C! C) ]) b* j+ K$ W3 G
: p# n$ s% K/ b  d0 k0 p+ m
录制装配过程的JA,经过对录制的代码进行简化删减后,如下,经编译后能够实现自动化装配。
  1. Session *theSession = Session::GetSession();
    3 T- Q5 r  {* l1 A7 b8 F" }* W& b8 I
  2.     Part *workPart(theSession->Parts()->Work());
    * N% n) V3 V3 r7 r. d
  3.     Part *displayPart(theSession->Parts()->Display());* ]" Q5 }3 q0 N5 T  W) v
  4.             
    ' o6 w0 A. k1 O9 A' _& Q, S
  5.     BasePart *basePart1;
    ! Y6 l  Q! o5 N* k
  6.     PartLoadStatus *partLoadStatus1;
    ' i9 U$ L# l: ~/ k0 R0 q( s
  7.     basePart1 = theSession->Parts()->OpenBase("D:\\sy\\model4.prt", &partLoadStatus1);9 p+ S2 e6 b) i: \: N, _( n: C
  8.     delete partLoadStatus1;
    3 |1 t3 g9 t% B
  9.    
    " \/ U  x$ @5 D# s0 U
  10.     Point3d basePoint1(0.0, 0.0, 0.0);
    ) C, [4 ]$ H9 r5 F& C5 _* V+ \
  11.     Matrix3x3 orientation1;! Y# }3 k0 E' g$ u# |2 z0 Q- P
  12.     orientation1.Xx = 1.0;    orientation1.Xy = 0.0;    orientation1.Xz = 0.0;
    / c' a+ R, \( f4 ~. Z1 J3 _" s" S
  13.     orientation1.Yx = 0.0;    orientation1.Yy = 1.0;    orientation1.Yz = 0.0;/ P6 B; u- `  e8 U( z) L! L( ~; |$ g  c
  14.     orientation1.Zx = 0.0;    orientation1.Zy = 0.0;    orientation1.Zz = 1.0;
    % `, a& M( \' P
  15.     PartLoadStatus *partLoadStatus2;
      K$ ?: o; I& h
  16.     Assemblies::Component *component1;
    $ _  c% @1 O) F* F9 S/ w4 `
  17.     component1 = workPart->ComponentAssembly()->AddComponent("D:\\sy\\model4.prt", "MODEL", "MODEL4", basePoint1, orientation1, -1, &partLoadStatus2, true);//添加组件
    ; {0 [: J  g; l
  18.    delete partLoadStatus2;    a. g* j, N8 X( ~4 {6 B# c
  19.     + R! a/ o0 `( w+ G6 i" S/ C
  20.     BasePart *basePart2;) e1 A8 I( g. m
  21.     PartLoadStatus *partLoadStatus3;
    ' W6 b& O& b9 b& ?$ K( C! k
  22.     basePart2 = theSession->Parts()->OpenBase("D:\\sy\\model5.prt", &partLoadStatus3);   
    " U7 D6 N1 x& G0 W7 O1 y% F
  23.     delete partLoadStatus3;    ; a7 f( p% g$ g6 J' z* b( u
  24.    
    - n- v. @. B: W! q0 h
  25.     Point3d basePoint2(0.0, 0.0, 0.0);- G; h( N$ x. F3 a$ X# ?' u8 {
  26.     Matrix3x3 orientation2;
    % l" Z+ B9 B1 y- a
  27.     orientation2.Xx = 1.0;    orientation2.Xy = 0.0;    orientation2.Xz = 0.0;. W% k! P5 A& X
  28.     orientation2.Yx = 0.0;    orientation2.Yy = 1.0;    orientation2.Yz = 0.0;  \3 W" O- r0 h9 N) P1 D0 G0 J
  29.     orientation2.Zx = 0.0;    orientation2.Zy = 0.0;    orientation2.Zz = 1.0;
    7 q3 k2 L- c0 e% o! ^
  30.     PartLoadStatus *partLoadStatus4;# S/ Q0 @+ m4 p5 `3 }; q8 R
  31.     Assemblies::Component *component2;/ ~9 T( ?9 c1 ?! O
  32.     component2 = workPart->ComponentAssembly()->AddComponent("D:\\sy\\model5.prt", "MODEL", "MODEL5", basePoint2, orientation2, -1, &partLoadStatus4, true);//添加组件- m; N3 G6 f  `( a% W9 y
  33.    delete partLoadStatus4;  
    + g7 y7 P- ~7 C5 T7 x1 j' k2 w
  34.    
    + x$ n6 i! u9 ~# i
  35.     Positioning::ComponentPositioner *componentPositioner1;
    - v$ _/ v; H% H
  36.     componentPositioner1 = workPart->ComponentAssembly()->Positioner();     # ~) C5 V0 Q, w5 k
  37.     componentPositioner1->BeginAssemblyConstraints();      
    5 Y! g8 k4 A5 w  [. D" _8 h
  38.    
    ( z2 Y0 n6 b- k
  39.     Positioning::Network *network1;" c( H1 g/ E- ~# F# u; {6 |- _6 X
  40.     network1 = componentPositioner1->EstablishNetwork();    3 s6 K% v: a+ r: @
  41.     Positioning::ComponentNetwork *componentNetwork1(dynamic_cast<Positioning::ComponentNetwork *>(network1));
      g7 o: _9 [$ `/ J# A0 }; `
  42.     componentNetwork1->SetMoveObjectsState(true);              * i, b7 J! a! B
  43.    
    0 m0 m9 M1 ~0 L, w# `2 M9 X
  44.     Positioning::Constraint *constraint1;
    . h/ z$ |9 y7 r: ]/ U
  45.     constraint1 = componentPositioner1->CreateConstraint(true);
    6 p6 N4 G4 m8 W% R: j' r
  46.     # T% E2 ~0 K6 s; _/ {( i$ i+ ^# _. h
  47.     Positioning::ComponenTConstraint *componentConstraint1(dynamic_cast<Positioning::ComponentConstraint *>(constraint1));
    + K7 L' T6 l2 T0 \' q
  48.     componentConstraint1->SetConstraintAlignment(Positioning::Constraint::AlignmentContraAlign);   
    1 X' S' `, }+ z( @7 r" O
  49.     componentConstraint1->SetConstraintType(Positioning::Constraint::TypeTouch);, M: y; z- _$ `* [  Y
  50.     & R: w% y* f9 @6 f
  51.     Face *face1(dynamic_cast<Face *>(component2->FindObject("PROTO#.Features|BLOCK(1)|FACE 6 {(500,25,25) BLOCK(1)}")));        , A7 Z8 f4 `7 M$ U
  52.     Positioning::ConstraintReference *constraintReference1;
复制代码
但是出现了一个问题,在上述代码中,进行装配的面是通过FindObject来找到的,不是我想要的那个面,而且FindObject函数参数是一个JA标识符,我无法给某个面定义JA标示符。如果我在建立模型时,我给某个面命名为FACE1。那么我如何找到我想要的面FACE1,然后用于代码' E4 [& y8 b- y  L5 |1 p
  1. constraintReference1 = componentConstraint1->CreateConstraintReference(component2, face1, false, false, false);
复制代码
其中上述代码中第二参数类型是NXObject *,也无法通过Ufun函数的UF_OBJ_cycle_by_name找到,因为该函数找到是FACE1面的tag,返回的类型不是NXObject *。/ G9 @# ?& G. k( F6 ~& T
问题:
- e# f" q9 k  p- ?: G! u! o& X& a  p1)C++中是否有某个方法通过某个对象的tag返回其NXObject *类型$ c; s5 a+ i% y# m* H
2)C++是否有某个类中的方法可以找到occurrence中的面(CreateConstraintReference需要的是occurrence的对象),而且返回的是NXObject *类型对象,可以直接用于CreateConstraintReference()方法。; K( Z* g0 G+ _; j! F
9 P& B1 J  X, K" y8 f+ X3 c
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

全部回复1

admin 发表于 2014-5-9 10:26:29

admin 沙发

2014-5-9 10:26:29

tag 可以通过 NXObjectManager 返回 NXobject
( f( V) Q/ B* H, o* |* `9 ]
. Z3 m1 L1 F5 t% c0 z8 a, A$ I
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复 支持 反对

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了