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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

+ u# ]/ D+ @) `3 t  mCatia二次开发源码分享: 获取装配所有组件列表# y+ i2 t. h- D( \
; c* T4 S! G6 z) n! p& _% j8 w

: s' J9 v/ B& K3 J$ G7 A[mw_shl_code=c,true]/* ----------------------------*/+ ~7 a0 b% D- E2 p. @
        /* 2. Retrieves Root Product   */
" Y. R$ H; j- G6 ?' F$ o+ f# X        /* ----------------------------*/
) n/ e5 v1 W4 a5 q; ^       
9 o/ v5 k( r4 J* v2 @        // Begin navigation throUGh the document => start with the RootProduct.
+ f3 ^, Z6 W! c0 f        CATIDocRoots* piDocRootsOnDoc = NULL;: a- C, e* h) k
        rc = pDoc->QueryInterface(IID_CATIDocRoots,: R. B: W* ~+ m5 _' S' ?8 r
                                      (void**) &piDocRootsOnDoc);& q. q! v3 x6 s: g/ v( m" e
        if ( FAILED(rc) ) return 3;
! z6 x3 X( e: n3 q# [        - P1 F/ j% i: `
        // get the root product which is the first element of root elements; N# w; I, f; y  Q; @& b. b
        CATListValCATBaseUnknown_var* pRootProducts =
; R8 n3 [( w& y! k& O5 E$ d. Y                piDocRootsOnDoc->GiveDocRoots();; S  L5 f, T; n& E6 }
        CATIProduct_var spRootProduct = NULL_var;: A+ n, H1 s" i% w' n
       
: u1 W2 ]6 G/ a; y* D8 N7 \; {        if (pRootProducts && pRootProducts->Size()): p4 D  t2 c9 ~5 m" Z; Y  q
        {  
2 D8 v# o1 s1 e3 E6 s$ m, b. \! \                spRootProduct = (*pRootProducts)[1];
5 b* y4 [) o5 e+ C3 x0 m) a- R                delete pRootProducts;- J& T) D5 y9 `1 t- S
                pRootProducts = NULL;9 h' w7 A3 J0 v$ i. ~' O. s
        }4 ]: o% {7 {2 {) i( @* o3 o9 |! X7 h
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ 8 [& w% A. q" i7 I4 m
        piDocRootsOnDoc->Release();' s- \) M; k2 n
        piDocRootsOnDoc = NULL;
$ n( S! S+ f1 p       
" L+ H7 H0 U" s9 D! J0 h        // Get CATIProduct handle on the root product.# \4 B) t$ b8 y$ u) ^- ~
        CATIProduct *piProductOnRoot = NULL;
" @  Z& I/ Y6 \7 X9 w        rc = spRootProduct->QueryInterface(IID_CATIProduct,9 e  F8 ~! D( j3 p1 W
                                               (void**) &piProductOnRoot);2 t$ S' Y1 |1 H. \0 J
        if ( FAILED(rc) ) return 3;
7 }* B$ ~! I& X( V  E: j0 `* v) a7 s4 @$ J  S
        /* ---------------------------------------*/
8 p8 Y3 p" j2 R        /* 3. Retrieves children under the root   */
5 E$ n- {$ v$ M) l0 ?        /* ---------------------------------------*/' o7 a8 l3 v* n% G8 Y
        1 ]$ }) U8 F& r1 w* G. I& @
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;0 N- |/ @2 v- D# ^7 {) m$ R' U
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;* f( _# H3 h0 O  ^+ ^
       
/ Y4 o; J5 O! ^) o& I        // then on a root product, get all the children agregated to it.2 H+ x  O& }% {6 m3 F2 o2 l
        CATListValCATBaseUnknown_var*   ListChildren =) I2 J2 v* R! x; }$ x
                piProductOnRoot->GetAllChildren();
1 C# [0 _$ A% [+ i# z& C. n7 k* R/** @anchor err_2 piProductOnRoot not set to NULL after release */
" f- @  _7 f0 }& p, p( [        piProductOnRoot -> Release();" [# ]; ^  ]0 e! j! p
        piProductOnRoot = NULL;' m/ E5 k' L/ Q2 k
        if(NULL != ListChildren)
: M- \) J$ A6 Q: C- J+ \& Y        {
& e6 `' f) Q0 s5 e% B2 [% I- N               
+ V# B& H" Y% m: w8 \8 O                int numberOfChildren = ListChildren->Size();
: o# H1 h, n9 H  t6 M                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
# M7 k, c6 R5 F! l8 I9 N, A3 ]
9 T) r+ [. v4 Q" M- Q1 S8 S6 _4 K                /* -----------------------------------------------------------*/
$ y6 n% Z5 K; h/ d0 ~! _                /*  4. For each child, get its partNumber, and InstanceName   */
) k+ W2 T! |: a                /* -----------------------------------------------------------*/
3 C1 {2 m" U& h- ^* k; I                CATIProduct_var spChild = NULL_var;
  {* H# K# u6 t; ~3 E, I                for (int i=1;i<=numberOfChildren;i++)
& B! W$ S7 u7 D/ v1 B' O3 R                {
- t  X$ |1 _# \                        spChild = (*ListChildren);
) `& b7 c6 b7 g9 G1 @/** @anchor err_3 spChild not tested before use ( if !! ) */ ; W/ ~) x! O4 W
                        if ( NULL_var == spChild ) return 4;
* g( r* }( V5 L4 u# P                        CATUnicodeString partNumber = spChild -> GetPartNumber();
( n* o- S0 _1 W, ~! ]. V                        CATUnicodeString instanceName (" ");1 q: `5 y( w6 g3 ~" v' P: u
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
" M7 {: Z. ~" J8 R                        if  ( FAILED(rc) ) return 4;
" I4 b0 p# e: O1 V1 u/ A. {                       
( Z! z/ `% F; h                        cout << " child number : " << i << endl << flush;2 Y7 S9 A. j, y. b
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
$ `; P1 @$ d9 A2 [* F                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
. x) \$ f0 l" Z8 n                }. k  M- h9 A* a; ?7 H! p
                delete ListChildren;3 Y. g- m3 V; e. o3 |( S4 S8 A
                ListChildren=NULL;
6 @- N7 q2 W7 }+ c& x        }        ( q& i4 r% h) t. m; d3 G
        /* -------------------------------------------- */
* P* y4 t; l' X8 f        /*   Ends the session                        */0 \+ q6 B6 P  D6 L
        /* -------------------------------------------- */[/mw_shl_code]
- }! W( L) `' R% A
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了