PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

& }4 O) h1 B  N5 k/ h! oCatia二次开发源码分享: 获取装配所有组件列表
/ f3 L# c8 e5 A% n. s
) x+ d  M, ^( \( }
4 \' q" _8 w/ p* h/ Z[mw_shl_code=c,true]/* ----------------------------*/
; k( u, s  x, o( L: u: A        /* 2. Retrieves Root Product   */
3 P" a3 f# [2 F  x        /* ----------------------------*/, n+ X  ~+ R9 ~9 z7 T
        / y9 m  N8 `2 Z8 r
        // Begin navigation throUGh the document => start with the RootProduct.
0 d8 N$ Y) F, h' F        CATIDocRoots* piDocRootsOnDoc = NULL;+ H1 b8 z; \- l7 f: |  Q7 t' x
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
% C- E" x, W* O; p                                      (void**) &piDocRootsOnDoc);
( h" n1 n4 G, r) E8 m: ]4 z& g        if ( FAILED(rc) ) return 3;
& i' Y. [/ {4 b# X9 ]        : _9 Y4 y3 e/ s" Y; y, `8 W" Y
        // get the root product which is the first element of root elements
" I; X* W. m5 A' w, H        CATListValCATBaseUnknown_var* pRootProducts = % w& j9 ~5 M/ D* R) N, ^
                piDocRootsOnDoc->GiveDocRoots();& n; P) z- N. X3 w4 |7 N! _) d  m) O+ N
        CATIProduct_var spRootProduct = NULL_var;
! c& C2 F. u, ?) b9 j. K* H* X9 P4 l        " N& K) H( D, o; ?1 L+ a; O
        if (pRootProducts && pRootProducts->Size())
1 Q7 p; T! ?7 b        {  " X! U4 l2 n% v! W% d2 f
                spRootProduct = (*pRootProducts)[1];
0 m# G( G- W9 M6 F) c0 O                delete pRootProducts;
! }& D4 P# `1 S) C) H7 c7 W2 w                pRootProducts = NULL;( Y1 i, @$ }. m/ K1 R
        }- a# F! S. ^4 ?. h5 O7 `
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ ( W4 Q9 f6 n! s# D
        piDocRootsOnDoc->Release();
! u7 U- b4 B2 |. q( M% P0 a        piDocRootsOnDoc = NULL;
+ [# H  k5 b. M7 R. o, Q, e        2 A+ L3 I6 h! t  z$ c
        // Get CATIProduct handle on the root product.4 P$ u& P& p$ i) J
        CATIProduct *piProductOnRoot = NULL;: T- W, F( `  i% x7 q2 x. R* F; J
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
$ ?2 e* F$ g" h7 v+ H                                               (void**) &piProductOnRoot);
3 [! L) f& R) ?+ `1 E        if ( FAILED(rc) ) return 3;; h, n' Q3 n; P' S! D# b# g

/ z  W2 W. z  x* L# Y( L3 L- s9 \8 l% G        /* ---------------------------------------*/% V5 |% e* }" {4 E; l- E
        /* 3. Retrieves children under the root   */  o- b( [8 `* C$ z$ h# o% K
        /* ---------------------------------------*/, `0 k0 l2 ^9 \7 Q& d2 q: }
       
$ M6 \& Q3 D. O        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;! k+ V7 P( [& P5 {
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
# Z: z- ]! U( ^2 _0 ]       
) \) {, f/ F  o$ \( K/ `% ~        // then on a root product, get all the children agregated to it.
9 m" H; H/ k# K" ~' C$ D        CATListValCATBaseUnknown_var*   ListChildren =
. T, [* H$ N2 w: T# t9 g( @4 u3 r                piProductOnRoot->GetAllChildren();7 f8 }3 V2 h0 J0 b* c
/** @anchor err_2 piProductOnRoot not set to NULL after release */   R1 u* F- t: n
        piProductOnRoot -> Release();
% |* ]# G' z. q) V5 E8 o; E) }        piProductOnRoot = NULL;
/ z- W( W9 l* q' Q! a        if(NULL != ListChildren)
: `3 p! `0 ]) B+ P7 Y" E/ B9 y& H        {5 z! T7 l: G* B9 t- L9 ]( [
                . {/ B0 r1 P3 |
                int numberOfChildren = ListChildren->Size();
, Q: I6 j! S" B1 z2 S                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
& Z1 @0 A5 W8 Q% ?- Y0 y) ]' s) ]" o; g# d, z
                /* -----------------------------------------------------------*/
0 q  t/ n7 [* j- U1 E                /*  4. For each child, get its partNumber, and InstanceName   */
% A( `0 \& `% U& |) a- [4 C0 ]                /* -----------------------------------------------------------*/
. ~. }& O+ X% K, r8 u/ g6 X# p                CATIProduct_var spChild = NULL_var;
& W, Z/ V0 v4 D  @                for (int i=1;i<=numberOfChildren;i++)
2 G* l( y0 p5 }- T3 c                {0 a7 t0 x4 ~" I8 b6 e6 L
                        spChild = (*ListChildren);9 W% e& Q  Y/ o7 C- V
/** @anchor err_3 spChild not tested before use ( if !! ) */
, l, L7 J1 W3 s- |, ?8 g                        if ( NULL_var == spChild ) return 4;+ |2 x& n2 Z: E5 T6 x2 U
                        CATUnicodeString partNumber = spChild -> GetPartNumber();, |& ]1 P, h' t8 }+ z- p2 h  a
                        CATUnicodeString instanceName (" ");# g! _6 W) D& {: j6 ?5 h
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;. v( H/ ?, \! F
                        if  ( FAILED(rc) ) return 4;- K' |  N$ y* a1 y' z/ M
                        ! _- s5 c) R# Q& X' H/ i6 [: z
                        cout << " child number : " << i << endl << flush;) x2 ^% ?- X# O% ^
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;' i; r# G2 D8 ]; ]( t! A  v6 A
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
) v7 S+ g1 e$ v1 k                }, P9 G( P+ P/ s9 q3 `: {
                delete ListChildren;% A/ d7 e: j2 l; \+ x  x4 u
                ListChildren=NULL;; @8 i2 b: ?9 b% R
        }       
/ x3 u' g: k3 c' j5 p        /* -------------------------------------------- */" h) l( N9 A& ?  N2 |& }
        /*   Ends the session                        */
" M+ u) T# a" t4 w        /* -------------------------------------------- */[/mw_shl_code]
) P( r) l) \+ V9 w# @, ]; N
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了