PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
* Q9 L0 x  E  D6 w
Catia二次开发源码分享: 获取装配所有组件列表
" _! d: w5 P1 G& ^+ p8 f3 ~' L; f$ |+ a, E* ~
8 r2 `! ]# e: Y9 j& K
[mw_shl_code=c,true]/* ----------------------------*/
' C  \) t  I" s7 Q4 x. L        /* 2. Retrieves Root Product   */( V% T9 ]4 B* a! w4 ~
        /* ----------------------------*/8 I' `: w2 |5 v3 S5 d) d% s
       
- O5 u" X% I# q: V2 d  r4 j* _5 v        // Begin navigation throUGh the document => start with the RootProduct.
) t7 l- P2 `- b6 J        CATIDocRoots* piDocRootsOnDoc = NULL;* ]9 D7 l) B9 S- V. y: V% M
        rc = pDoc->QueryInterface(IID_CATIDocRoots,! F% }! G- ^' p& ?7 i
                                      (void**) &piDocRootsOnDoc);5 [4 f+ A0 I+ J. T4 `; d
        if ( FAILED(rc) ) return 3;0 x" B& M  ?' l/ N* _( M' k2 ~2 @
        ( F; b1 V( a/ p
        // get the root product which is the first element of root elements
4 O/ \% C5 o2 ?        CATListValCATBaseUnknown_var* pRootProducts =
  J) Z  ]) }- |' Z% _8 N4 z                piDocRootsOnDoc->GiveDocRoots();
- [% ]3 ]0 S. a        CATIProduct_var spRootProduct = NULL_var;+ f" d& @, z# Y( z; k* r) w
          B) a0 p8 }3 P( B9 i
        if (pRootProducts && pRootProducts->Size())
. _# Z+ ]$ c' D/ H        {  
) ^" w; R# G% Q                spRootProduct = (*pRootProducts)[1];
, n% y2 L6 s4 H                delete pRootProducts;
' t0 j6 n) c$ k; o; l                pRootProducts = NULL;3 ?4 C5 j. F6 Q: n# v" @; n
        }
. q' h8 i2 r9 S; c: N/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
( ^- W7 C0 s( C2 }4 I  K% z        piDocRootsOnDoc->Release();
5 u$ Q0 D8 S& g: }  G" O        piDocRootsOnDoc = NULL;
  Y; m7 H# Y4 H2 D8 O% _4 w       
! i3 [4 J7 \5 [, N        // Get CATIProduct handle on the root product.
) H% X( P6 }- ^! p) _: X        CATIProduct *piProductOnRoot = NULL;! Y) {) I( i( s5 l( }% n' W1 k
        rc = spRootProduct->QueryInterface(IID_CATIProduct,, L0 }7 A* w: F* T2 Z; R0 b
                                               (void**) &piProductOnRoot);2 Z/ J7 m/ W' ?$ {2 Z
        if ( FAILED(rc) ) return 3;
; J3 M% _2 w4 u! a4 {' ]3 }" A$ J9 M# J8 E. S9 ]
        /* ---------------------------------------*/
) A% O& s; U- R2 A7 f        /* 3. Retrieves children under the root   */
2 S& u- J3 u) v        /* ---------------------------------------*/  {2 S* o8 B. I( o% Z0 V2 {) E
        . C7 A1 J7 R, @+ _, q" T0 L
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;) p' M: x0 P3 T$ n$ G
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
& a$ h: L# F" {! s/ d        : n+ E/ k) b3 E7 e+ F/ [! X
        // then on a root product, get all the children agregated to it.
" F1 L+ }6 g: V# Z        CATListValCATBaseUnknown_var*   ListChildren =
+ @4 l  {4 e$ ]  D0 ?/ ^8 `                piProductOnRoot->GetAllChildren();
, E+ h( _: w1 H" s2 O8 k/** @anchor err_2 piProductOnRoot not set to NULL after release */ ) b% |2 t( |2 I. ~
        piProductOnRoot -> Release();
, R% W% B# U0 M- p1 K        piProductOnRoot = NULL;- c0 \1 t& P+ N
        if(NULL != ListChildren)
$ ]) M* W: Y: F2 J3 m; t$ X  w2 a        {
+ F0 p% [# t6 c9 d8 V6 H                : ~% B' t  B# o) O
                int numberOfChildren = ListChildren->Size();
) v9 `9 E6 t. {                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
+ i9 H( S+ {0 ^" w" g: b& e; T6 q; L5 x$ o/ [9 i$ q
                /* -----------------------------------------------------------*/' N6 Q! O6 d* W' Y1 |3 C5 c
                /*  4. For each child, get its partNumber, and InstanceName   */9 _: c' R4 a7 p" q2 Z
                /* -----------------------------------------------------------*// j: x/ o, T+ f
                CATIProduct_var spChild = NULL_var;
/ ]8 _& a3 l, I" c+ w' I                for (int i=1;i<=numberOfChildren;i++)
- T4 B2 I2 `- Y; A) M7 z                {% e2 o( ]/ |% z
                        spChild = (*ListChildren);
- r: T9 Y8 ], w/** @anchor err_3 spChild not tested before use ( if !! ) */ 4 A( I" N) @) X
                        if ( NULL_var == spChild ) return 4;
/ U+ i, g' ?* Z+ B+ i+ w" m                        CATUnicodeString partNumber = spChild -> GetPartNumber();# v& W2 s- v( h5 u5 y1 r% A, R
                        CATUnicodeString instanceName (" ");
0 p! K- U) M  J; K) [2 Z9 k7 O- y                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
8 a2 y7 z$ H3 @# ^; e                        if  ( FAILED(rc) ) return 4;& ]8 ]4 S9 q% G  m
                        + s6 H. o) _+ ~. d8 m$ q) W
                        cout << " child number : " << i << endl << flush;
) r" v& z) l5 e3 L                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
2 a# \# F+ z) K9 j# @# m6 J6 O                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
7 ?& |0 {8 q( H                }. Q+ G2 r6 X% b% A, L  B( d
                delete ListChildren;: R: l' J- G3 u5 Z7 q, i) D# B! e
                ListChildren=NULL;
( H: D) n' B' e, x        }       
8 G% u* P( Z) H8 Q* `# N2 V/ P        /* -------------------------------------------- */0 E% q; i0 R2 ^. n* ^
        /*   Ends the session                        */+ k& O: a& i8 W3 v% _
        /* -------------------------------------------- */[/mw_shl_code]9 K* R" O& j; `; ?! ^* |# k7 q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了