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

Catia二次开发源码分享: 获取装配所有组件列表

[复制链接]

2018-1-10 10:12:25 2542 0

admin 发表于 2018-1-10 10:12:25 |阅读模式

admin 楼主

2018-1-10 10:12:25

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

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

x
0 b3 ~$ s* \+ Y+ P4 P
Catia二次开发源码分享: 获取装配所有组件列表5 x, q/ I5 N9 u. S/ \/ j
/ b3 i/ D, k& r# {) F
, S$ }4 t/ |2 o: x4 q: i; K! l
[mw_shl_code=c,true]/* ----------------------------*/; n/ I) z9 |% J- x( Y
        /* 2. Retrieves Root Product   */
2 Q- {1 F2 Y: S" R5 k        /* ----------------------------*/
' Z, c$ X% w: H4 ^3 {' q       
5 X/ m1 V1 W$ h        // Begin navigation throUGh the document => start with the RootProduct.
! Z9 W0 r, S5 F' [$ L1 Q5 N        CATIDocRoots* piDocRootsOnDoc = NULL;
6 ]3 v9 ^1 S6 M. a: Y0 |        rc = pDoc->QueryInterface(IID_CATIDocRoots,8 R" J2 j! z, X
                                      (void**) &piDocRootsOnDoc);" k( F. a) A& n+ \6 N
        if ( FAILED(rc) ) return 3;
7 j) W3 u$ o  ~& w- ]5 Y. @5 S9 U        9 T7 M0 f) N. Z" b8 t
        // get the root product which is the first element of root elements
6 [: h# m- n8 q/ O. e3 }        CATListValCATBaseUnknown_var* pRootProducts = $ M7 ?0 Y/ i0 ^6 A) s" H
                piDocRootsOnDoc->GiveDocRoots();1 b( I, Y/ ]( O. t8 P! g1 [8 b$ g9 ~
        CATIProduct_var spRootProduct = NULL_var;
; t# y$ T% P7 S" D( C1 P' \  u, M6 {       
3 m: n" H2 l  v* [7 b" u8 c; ]2 O        if (pRootProducts && pRootProducts->Size())  z0 x7 m( q9 Y
        {  " K, G, ?: k, ^  o8 Y
                spRootProduct = (*pRootProducts)[1];0 ?% V5 F" G: |0 D
                delete pRootProducts;- y% P; c  d3 e
                pRootProducts = NULL;
+ c+ t6 p  d& @        }
  @9 n- Z* e9 V4 a2 x/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
, r, K2 p# t  {, j: f7 M        piDocRootsOnDoc->Release();
3 K; @7 b4 Z5 [7 u  A        piDocRootsOnDoc = NULL;
: O1 d) h2 E1 \" \       
, M& _3 m7 u+ x; Z        // Get CATIProduct handle on the root product.$ T9 b' Q) P( k% S
        CATIProduct *piProductOnRoot = NULL;
) }/ G& s3 L" m, w' A* f        rc = spRootProduct->QueryInterface(IID_CATIProduct,
. e+ _$ t/ k1 |1 U, Z& z5 a                                               (void**) &piProductOnRoot);, I) \4 x6 {1 s; i+ H! Y
        if ( FAILED(rc) ) return 3;
. o: G% x, [* f- g) {
9 T: x+ o; ]: A1 b9 f        /* ---------------------------------------*/
0 {1 d1 @  |) M' b$ ]        /* 3. Retrieves children under the root   */% Q/ i; s) h) i* l" L" a3 }
        /* ---------------------------------------*/. Q& \% g6 q0 W# m1 W  Z
        ( _: v/ @2 {: O) F; [
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;
/ d3 Z6 b# y* z2 p  b+ Q        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
- c4 P* e. [# [. O        % I& {. x0 C# Y& J2 F$ S0 ?
        // then on a root product, get all the children agregated to it.
4 h' d2 j8 u7 @2 k1 G( ?. \! P        CATListValCATBaseUnknown_var*   ListChildren =
1 `1 u" ^. V$ M4 Z6 E  x                piProductOnRoot->GetAllChildren();; a& T  A: G" P& D- x& z9 n. a
/** @anchor err_2 piProductOnRoot not set to NULL after release */
" z. u* |) }. z: U8 T        piProductOnRoot -> Release();+ ?1 p8 ^: g5 |& T
        piProductOnRoot = NULL;
# `; X6 |5 R! Q9 a        if(NULL != ListChildren)- U, b/ B3 R% z! t7 l# V8 Y; ]* V9 E
        {7 h! ?* D7 D1 q! Q% H; ^  k
               
2 O8 J8 g2 q) X1 t: v* x: j  s+ h+ P                int numberOfChildren = ListChildren->Size();
3 n) o5 n3 P! x* @1 u" a                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;7 H3 W/ b! @; u  H
/ N6 D$ P' m2 w) B5 k( D
                /* -----------------------------------------------------------*/
* M2 w$ H+ u8 A% c1 ?                /*  4. For each child, get its partNumber, and InstanceName   */* L) M8 p# }  }
                /* -----------------------------------------------------------*/
$ _& r) {4 ~# @" ]. M7 M                CATIProduct_var spChild = NULL_var;
% B. u) ]: |+ [, p                for (int i=1;i<=numberOfChildren;i++)
# ]1 s( J; l2 n' @& ~                {
* p0 R+ e9 [1 S7 X: Y' K* U                        spChild = (*ListChildren);4 S& u5 o; S5 l3 p! k
/** @anchor err_3 spChild not tested before use ( if !! ) */
) A, O* I: W7 w8 ~                        if ( NULL_var == spChild ) return 4;+ ]/ ?1 I1 @9 ^( [: e: ]
                        CATUnicodeString partNumber = spChild -> GetPartNumber();
9 X0 k  S6 V; Y4 l2 L9 A                        CATUnicodeString instanceName (" ");, Y& }9 ]+ r% j0 ?' O- w( u
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
" {1 I& z9 Q6 R+ i; C/ _7 V                        if  ( FAILED(rc) ) return 4;- `- X( Z; s0 I% @" l6 ^. {& ~
                       
* _# D2 _" G" N                        cout << " child number : " << i << endl << flush;: U/ N8 ~# M; _# a9 k
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
" D& d# P- u' }# v                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
) a1 _4 Y3 n) {$ V, U                }
- Z( l3 J1 J7 l                delete ListChildren;0 b9 c# |  _- G, i/ a& u
                ListChildren=NULL;% w' W7 |& S! G: r8 {" |1 W+ w
        }       
  q" \+ G5 s: @- W3 d        /* -------------------------------------------- */6 {# e. z9 r( L
        /*   Ends the session                        */' L8 X5 y* s" g2 B- {
        /* -------------------------------------------- */[/mw_shl_code]& Y3 H* |$ k5 J- ~$ X
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了