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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

2 V3 b3 p2 ?# {" `; ECatia二次开发源码分享: 获取装配所有组件列表
# g( H3 r$ w& H" Y# K- Z8 t4 m

1 ^$ O! Z9 s2 P& v[mw_shl_code=c,true]/* ----------------------------*/
7 X' o" ~# e# k        /* 2. Retrieves Root Product   */
" w5 }% }4 m' @1 A: r        /* ----------------------------*/
) N( c1 I9 L' @6 J$ I8 b3 H  }        - v3 W3 m- u7 c
        // Begin navigation throUGh the document => start with the RootProduct.& `, u6 R: B  R, g9 W6 L: ~
        CATIDocRoots* piDocRootsOnDoc = NULL;' w2 u9 g& p7 I2 f9 n$ a9 J: ^5 ]% z
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
: q' i7 G9 v  D/ k                                      (void**) &piDocRootsOnDoc);6 V/ A1 H3 G4 E3 N3 |. a# a' z* Q
        if ( FAILED(rc) ) return 3;" {5 `2 }3 D5 V. O! g, S, m% J
        0 S  w" A; C# F" n
        // get the root product which is the first element of root elements
0 o/ h( x' y6 i; J        CATListValCATBaseUnknown_var* pRootProducts = ) y0 U  E6 M1 g- m( r
                piDocRootsOnDoc->GiveDocRoots();8 O& D1 [0 z4 d1 D& x, N
        CATIProduct_var spRootProduct = NULL_var;- p- u* `. a: U& _$ E9 y' R
        . N+ l/ o* K; s: s# l* j
        if (pRootProducts && pRootProducts->Size())7 m# _4 W$ p0 `6 p
        {  
. S, z+ F" _2 @. U& M9 c$ @                spRootProduct = (*pRootProducts)[1];) s4 k6 H3 a2 L" U8 |7 T
                delete pRootProducts;
9 S+ d1 E  z- s$ J, I* B/ t                pRootProducts = NULL;5 |) J9 h3 L) D( O, M4 q: Z7 v5 w+ ?
        }  E: s  ^% k% z2 u
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
9 s* J  d" [$ l9 g1 v: Q5 T        piDocRootsOnDoc->Release();% _6 d+ c. I! @
        piDocRootsOnDoc = NULL;
( u  S5 i* L' u6 @        3 }3 P+ M6 j3 d; t( G8 p" e
        // Get CATIProduct handle on the root product.
* d7 O5 f4 {; _  S# h; C        CATIProduct *piProductOnRoot = NULL;+ W& _2 h' M7 V" \! N. H2 P
        rc = spRootProduct->QueryInterface(IID_CATIProduct,# G- S; h" f. M! `
                                               (void**) &piProductOnRoot);
' ?  a8 j: [  Q# O- [        if ( FAILED(rc) ) return 3;8 Y; V; I# b* k4 l, [- h& s
% L# S- s  O$ A5 \( d1 J
        /* ---------------------------------------*/% f/ W, }' I( Y9 S5 d* m0 h) Q# C. Q
        /* 3. Retrieves children under the root   */. N7 M& p$ P/ e
        /* ---------------------------------------*/
  f% ]  l" X; M9 k: a/ v) X        ( a/ e& e6 N/ T' R; Q7 W3 b! n
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;# E8 @0 Q& p4 D; i1 U( o3 U
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
; C! O& L1 W$ s, q! b- N       
7 z3 t' }5 g6 x5 x9 A* {  Y        // then on a root product, get all the children agregated to it.) B. f/ F, D7 d" O  l+ \9 f
        CATListValCATBaseUnknown_var*   ListChildren =9 ^9 r* t, {5 T( |+ x& L
                piProductOnRoot->GetAllChildren();9 b7 A$ _; z$ S9 y
/** @anchor err_2 piProductOnRoot not set to NULL after release */ & e5 {- R9 M) h2 W, t! i
        piProductOnRoot -> Release();0 K  p8 v) q: T0 R8 a
        piProductOnRoot = NULL;9 }2 _2 {) y  E2 N5 v7 {
        if(NULL != ListChildren)
, |& y' `/ M& N        {
: n$ T/ a( X9 S1 P/ l- {9 i: @# ?                & p, {3 m6 J6 @6 x5 x3 z
                int numberOfChildren = ListChildren->Size();2 W2 X2 L# b4 B( [! n$ n' z) o
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
* x# q' r. H* N* `# b2 ?- `
8 s4 U9 p% K" ^7 m$ S                /* -----------------------------------------------------------*/
3 h) ]! b1 N5 a( c' _3 @                /*  4. For each child, get its partNumber, and InstanceName   */
0 b. E; B, k$ R                /* -----------------------------------------------------------*/
5 f6 B4 k2 j$ p8 S! K1 J                CATIProduct_var spChild = NULL_var;- G+ t; N9 b  t( X' `3 _
                for (int i=1;i<=numberOfChildren;i++), i$ b& ?6 P& X5 a
                {! @8 b5 A) L( _
                        spChild = (*ListChildren);
7 O% ^2 V4 d8 [1 e* K/** @anchor err_3 spChild not tested before use ( if !! ) */
/ V+ K/ ?; J$ F: U7 P* R                        if ( NULL_var == spChild ) return 4;) \5 l  i6 i3 k; A! }0 y
                        CATUnicodeString partNumber = spChild -> GetPartNumber();
7 [2 f2 y- L: j3 |' V+ v                        CATUnicodeString instanceName (" ");
3 i# ?/ [# `) K: x; p& \                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
: y" E( y9 P( @/ ]+ D                        if  ( FAILED(rc) ) return 4;% X; B) t# T8 e* ~# g, s- }
                        4 |% `. P5 s0 T
                        cout << " child number : " << i << endl << flush;
5 l3 j( B' |3 |  T9 m  l" K                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;! A( \. S) v% o- H3 }2 _
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
. j) J& U2 d# r& ?3 h0 @                }
. B  B$ X9 E& i4 ?+ q' g                delete ListChildren;2 I, Y: C; ^" w* Q0 ~
                ListChildren=NULL;
' @1 p* U6 y& n# j6 x" H+ Y        }        6 U% f% _# r) n, {! P
        /* -------------------------------------------- */
+ d9 g- p& ]! \+ w- ?- w        /*   Ends the session                        */
  b) h& u# A- e        /* -------------------------------------------- */[/mw_shl_code]5 R: m& ~1 E7 p6 N* |7 @: 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二次开发专题模块培训报名开始啦

    我知道了