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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

8 G! d) I7 G* Y. z9 CCatia二次开发源码分享: 获取装配所有组件列表: D: R3 _4 x- p) t4 i- I
, @: G/ V( B+ u

* J, ~) E9 V" j, h8 R4 _[mw_shl_code=c,true]/* ----------------------------*/( ]& A2 W7 p+ L) o" p. W9 y! w
        /* 2. Retrieves Root Product   */
" H7 p0 K8 E! n# L        /* ----------------------------*/
8 E' t9 o. |$ V1 w; i        # v1 S) h+ d" r) k( E7 f* b" r' x
        // Begin navigation throUGh the document => start with the RootProduct.
( X7 R3 U5 m! z" `, o  K        CATIDocRoots* piDocRootsOnDoc = NULL;, m7 L5 I' Q# Q$ k* Y
        rc = pDoc->QueryInterface(IID_CATIDocRoots,8 W* Q3 R: a7 C, }
                                      (void**) &piDocRootsOnDoc);1 X; R8 ~. l' K+ e" q) A8 I' T! t
        if ( FAILED(rc) ) return 3;4 h, o" L( t, v% N2 T) T- B
        " D7 |# j7 C" t7 |7 r. Q& ]  a
        // get the root product which is the first element of root elements
9 [2 e" ?, S, [: K( H9 |        CATListValCATBaseUnknown_var* pRootProducts =
8 j7 Z3 c  @- Q( E/ ^                piDocRootsOnDoc->GiveDocRoots();2 N2 ~1 g  y/ j' J& E0 r
        CATIProduct_var spRootProduct = NULL_var;! R, H' k$ R8 X. D/ P7 _* M2 z/ q8 R
       
% F6 x8 z5 T& U) g        if (pRootProducts && pRootProducts->Size()). U' d" A' H+ ~; x; L! o; \
        {  : ?- y8 ^  E5 W' U
                spRootProduct = (*pRootProducts)[1];1 m/ D! l# z+ Y! o# ~! j% B5 l5 @) J
                delete pRootProducts;& n7 ^. I- h& h5 p& E3 U+ @
                pRootProducts = NULL;( P" V/ ^: b7 j  F: W
        }
: j) I2 M+ I" D2 s# a/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ 2 O$ k$ Q& z! v( A; w
        piDocRootsOnDoc->Release();
( o' x6 u3 G- p3 c        piDocRootsOnDoc = NULL;
# f& w7 }# G/ W' E        & R" R. l2 y4 h0 T+ g/ ^
        // Get CATIProduct handle on the root product., k1 z- B" Y5 Y3 l, H' E% ]) d
        CATIProduct *piProductOnRoot = NULL;  E; O5 V- u% H  S, A
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
9 k4 w/ |! C4 k- L" H2 H$ {                                               (void**) &piProductOnRoot);
1 @3 H7 R8 A( [' o3 {2 o3 I5 G        if ( FAILED(rc) ) return 3;2 ^5 [# X4 M3 E  i1 T  H1 B

. o0 ~/ T+ D4 H. r: q        /* ---------------------------------------*/
& q" X$ T9 I$ q: |: S: i        /* 3. Retrieves children under the root   */
8 m+ O$ ?5 r+ _, ~' C! Y0 }        /* ---------------------------------------*/
' D& E( F$ k4 C9 W3 r7 A       
/ C9 z7 y+ T# E- b" c/ i9 x& G& w        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;
: O1 R& S! L+ O0 l7 @- t        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;% l% T& d/ T! V( I8 t# K4 t+ x3 J
       
: _4 C- \) V" o$ [$ H        // then on a root product, get all the children agregated to it./ b& E, {! t' V: R% Z2 p" z$ m
        CATListValCATBaseUnknown_var*   ListChildren =5 w9 ^, O3 [- N$ C% l
                piProductOnRoot->GetAllChildren();
8 _2 U* u: T! b( C/** @anchor err_2 piProductOnRoot not set to NULL after release */ ) e$ E: n- J5 G6 b. g' g1 z
        piProductOnRoot -> Release();
9 w- p5 ^0 X, P, M! F* A        piProductOnRoot = NULL;5 U1 s4 o* [! x$ M1 }, d- H% `
        if(NULL != ListChildren)
' N0 r6 w9 Z! |8 @) G' K        {8 w! \: w: q2 U3 T! \' F9 k
               
! D8 F  ]# r- \                int numberOfChildren = ListChildren->Size();/ ], t# M$ P$ {, ~
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
2 W" e; V( C1 ^
  t  Y1 c0 k  \                /* -----------------------------------------------------------*/
! M- x- P, f  e) R2 M! o                /*  4. For each child, get its partNumber, and InstanceName   */
$ ]  y4 N, S& r! w                /* -----------------------------------------------------------*/
' z' |6 K# H: f- N                CATIProduct_var spChild = NULL_var;
' A: w, j! e: R2 X0 L& U                for (int i=1;i<=numberOfChildren;i++)! |8 L2 g3 C" d1 D- x# l  S
                {
/ y5 G! e" W5 d: P* E! D$ _7 a                        spChild = (*ListChildren);6 C6 |. ~8 F# I8 D
/** @anchor err_3 spChild not tested before use ( if !! ) */
% n% t1 ]/ z7 [* U. Z                        if ( NULL_var == spChild ) return 4;
- f: q0 ~, W7 d3 j2 X* R/ ]; Y                        CATUnicodeString partNumber = spChild -> GetPartNumber();0 D8 L2 _8 `7 Z; j. x
                        CATUnicodeString instanceName (" ");
  A0 y( X1 U9 W/ f* L6 i                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
) a6 v& g2 J2 v/ b8 i+ r/ O                        if  ( FAILED(rc) ) return 4;1 Q- G& w2 T* A- O; B  H
                       
+ I. f+ ]; |$ A. i# s7 V                        cout << " child number : " << i << endl << flush;
; R. `5 Q: ?+ {                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;8 j/ _, X' |/ H& X8 o2 U- e
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
( W- N# T+ F  b0 _5 [                }' b+ q+ H3 e3 w
                delete ListChildren;* N; z9 L& v* a
                ListChildren=NULL;
5 g; m! G4 Y2 P+ ]$ x        }       
9 L, {2 p4 G: f' u* N. G, R6 d+ g3 i        /* -------------------------------------------- */5 ?# g' Q3 W6 o1 [: B' j
        /*   Ends the session                        */
# q1 `9 N$ O5 t5 N5 T2 ~0 b        /* -------------------------------------------- */[/mw_shl_code]$ _6 ~0 j5 `6 W( j% o- K
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了