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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
! P5 Y& [& ^/ h! p0 R" b
Catia二次开发源码分享: 获取装配所有组件列表- ]6 n8 G. U. Q
' q- R% p4 ]# t* |8 ^1 k+ n

: }: A$ D) A4 ?0 u8 g* l[mw_shl_code=c,true]/* ----------------------------*/
9 p& p' D$ M' x2 A5 U$ S        /* 2. Retrieves Root Product   */
& t- M1 }4 P& ^% q9 T5 e        /* ----------------------------*/
. K) m' t% d$ w( u% T/ D( V       
- E( A5 }  ?( `/ n& R# ^! T  H        // Begin navigation throUGh the document => start with the RootProduct.+ O- c- ~  G* X1 F3 T
        CATIDocRoots* piDocRootsOnDoc = NULL;6 k$ w; _9 V3 W$ A$ U( ^, L; ]$ d
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
2 a7 n+ e0 W( L0 O/ i4 D                                      (void**) &piDocRootsOnDoc);
# Y) l) E- A0 h4 @* u# e        if ( FAILED(rc) ) return 3;* _  {' W3 z+ H1 u. M
        ) F: Q6 U1 \: j! m% C0 C
        // get the root product which is the first element of root elements
8 _8 A$ ?. r! s/ Q$ p# S$ }3 |; v        CATListValCATBaseUnknown_var* pRootProducts = ) }  F& k3 t. g: w  {" g
                piDocRootsOnDoc->GiveDocRoots();
. }8 V: W# V# q. p7 ~- O- \1 r        CATIProduct_var spRootProduct = NULL_var;! C: o# b2 E! S$ `
        & P! L& @/ P5 Z6 u- h4 N# K
        if (pRootProducts && pRootProducts->Size())
: |% s% r9 a2 b        {  " Y  ~6 p9 n' M4 g9 X
                spRootProduct = (*pRootProducts)[1];
# T& i( d2 g7 n2 I# `1 l                delete pRootProducts;
* F; ^% M6 X# z' }/ C* R: D8 ^                pRootProducts = NULL;0 ~% R, M& A5 L' X; }
        }
- ^7 K* z5 A. X( O/ K" N$ }0 s/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ $ H. L& P( c, ^( q5 V% ~$ J- K
        piDocRootsOnDoc->Release();
! O* h  H4 Q1 h% [( P        piDocRootsOnDoc = NULL;
2 q4 q" \. I6 L  t; \       
9 F3 J0 H4 m8 `$ ~+ a* `* P        // Get CATIProduct handle on the root product.1 X# g4 V9 G) o; h$ j3 W. O) }
        CATIProduct *piProductOnRoot = NULL;
% n7 ]" d4 t9 k/ c) Q        rc = spRootProduct->QueryInterface(IID_CATIProduct,5 o' H1 m6 E- k( s* {
                                               (void**) &piProductOnRoot);% T  }4 O; e5 R+ t  P
        if ( FAILED(rc) ) return 3;
8 u1 i% Z# U$ I4 ~9 O- [, z. I" r& [" b, a1 L- q4 B6 `* |
        /* ---------------------------------------*/  g" C" [$ I0 W
        /* 3. Retrieves children under the root   */, T- k8 B; ^* r' ^7 W$ M4 Q
        /* ---------------------------------------*/
/ \) |" K/ X" ^% L3 v5 k  A       
0 y2 I  K# z6 r: b, q( J+ ]! t        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;
4 t2 ^  n. i9 ?( P        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
1 h0 U6 W  i% m8 H- ~$ y        + e* E0 j9 _& Q2 j& B! }/ V( E
        // then on a root product, get all the children agregated to it.
( t+ R- Z6 v/ ^$ @" n( _        CATListValCATBaseUnknown_var*   ListChildren =
- M9 t( I- ~- C) _" y                piProductOnRoot->GetAllChildren();
& \# I( G5 S7 b5 y' i/** @anchor err_2 piProductOnRoot not set to NULL after release */ , p# g* x/ w5 X3 f
        piProductOnRoot -> Release();
9 G2 G6 O( X9 x  V0 K. h% [        piProductOnRoot = NULL;6 M3 m8 m& j. {, L$ G
        if(NULL != ListChildren)% X) q" {( y- @! @" ]1 B3 g
        {
5 q, U& P6 y6 n, t9 A# ~6 P                5 L; X/ K, P% M% `
                int numberOfChildren = ListChildren->Size();) v$ ?: v  k' j! `1 P9 ?- u1 G( G3 {1 M
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;- @6 \: I& k; q3 \0 v+ q( l# A1 Z
9 {2 M' Q6 u" ^
                /* -----------------------------------------------------------*/
9 m0 {' b9 x. C) J                /*  4. For each child, get its partNumber, and InstanceName   */, U( C' N" E7 z* E6 t* M$ u) a7 n
                /* -----------------------------------------------------------*/
* `  C2 Z; U  q: R: m                CATIProduct_var spChild = NULL_var;
) L; G1 O: Q% e- B' e                for (int i=1;i<=numberOfChildren;i++)
# e6 x% C" M; S- \0 i5 ?7 w5 h                {
$ d  Z6 C, z! R2 R1 U0 M                        spChild = (*ListChildren);
3 U" U: r6 X  ], h" e. D  H+ G/** @anchor err_3 spChild not tested before use ( if !! ) */
) U3 |0 {2 p7 c' @3 @                        if ( NULL_var == spChild ) return 4;4 T% s! t2 q# b/ y2 I6 l, N; e
                        CATUnicodeString partNumber = spChild -> GetPartNumber();
, H( t! i# X3 l. j: \1 b9 v                        CATUnicodeString instanceName (" ");
" C+ v$ e3 @  Y% l% r                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;" h" j$ |# p& ]5 u
                        if  ( FAILED(rc) ) return 4;$ S4 }) r0 m8 [8 |
                        ) I: u4 n; D; W; Z+ T) r# j6 `
                        cout << " child number : " << i << endl << flush;2 B7 I8 z6 `# O& ~' H8 Q0 E# }
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
- B9 h, E. l# t6 j                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
5 ], h4 ]3 C( [) v2 c1 w- n( D                }
9 G( d% f& G; @' z" Y& e                delete ListChildren;) q  w, |! u6 }3 X
                ListChildren=NULL;
5 _% v. H" ^/ W; L3 e$ G; [        }       
4 r8 Y) g0 a+ z% c* U/ u        /* -------------------------------------------- */% `: z: }- x. ^8 ~: N$ A3 L
        /*   Ends the session                        */
6 k. ?' z- B$ T( b        /* -------------------------------------------- */[/mw_shl_code]
" U! L* n* Q+ s6 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二次开发专题模块培训报名开始啦

    我知道了