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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
' q. b  d8 _3 D- [' R# c7 n
Catia二次开发源码分享: 获取装配所有组件列表
& m* g9 a) u8 {0 n3 l4 X1 o. e; i4 N5 j5 h+ ?1 @6 ^" X  t

& ~0 H# t, ~( x' o* I+ @/ f[mw_shl_code=c,true]/* ----------------------------*/
# v( `0 S8 x- E8 h5 @        /* 2. Retrieves Root Product   */
/ |/ ~( i/ `% C) g& E0 A( W        /* ----------------------------*/9 ^' z; H( K  G, o$ n  |' H
          t, z1 F" |7 |+ h! w' d. m- O
        // Begin navigation throUGh the document => start with the RootProduct.
# ]2 D0 K! T/ _% C% x; t5 U        CATIDocRoots* piDocRootsOnDoc = NULL;  L* X- o" v7 Q$ N! v( o8 K
        rc = pDoc->QueryInterface(IID_CATIDocRoots,7 Z' w- S: D7 O3 t8 L4 b
                                      (void**) &piDocRootsOnDoc);1 V5 y) H6 h1 W3 u" a
        if ( FAILED(rc) ) return 3;
3 e+ c2 U: f; p# a- x/ H% b        3 g4 z4 c) N) x6 _- y% O2 ]% R
        // get the root product which is the first element of root elements
( k; {4 R' G4 v3 l2 m. N& ^        CATListValCATBaseUnknown_var* pRootProducts = 8 ?, v" Z# C  ~' g" C+ ^* _8 r6 L" I
                piDocRootsOnDoc->GiveDocRoots();
8 O% F# y! e2 ?8 }( h) a- E3 X        CATIProduct_var spRootProduct = NULL_var;
; v  |5 v7 G6 |' H! v' ~       
7 t+ ?' M/ a# ]8 i( D9 N        if (pRootProducts && pRootProducts->Size())7 d. H, H6 Z' e$ a
        {  
8 K6 m" o* N: d/ t8 Y" c                spRootProduct = (*pRootProducts)[1];3 U) Y; i" [1 F$ K- j2 z  A+ P
                delete pRootProducts;
. [* m) a( `) G) Q8 Q                pRootProducts = NULL;
  V" h/ ^  T' ]- d) ^+ c        }( S) j& c3 S, z; o; @5 M0 H3 K" l
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
: M9 ?( N6 `# v( L) E7 z, N0 h5 P        piDocRootsOnDoc->Release();) T) }" E7 e/ |( j. j9 S+ {) F
        piDocRootsOnDoc = NULL;
0 p/ t) b2 X" Q+ H) A3 N       
+ D* j# u5 P  ~# [; J: {        // Get CATIProduct handle on the root product.
% J) X- Q; y% _+ s! g7 n4 I        CATIProduct *piProductOnRoot = NULL;  p1 T1 X' U4 E4 |
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
/ I5 h8 A8 w) ]) i1 O                                               (void**) &piProductOnRoot);& u4 j6 K8 G; L( ?# q8 ^
        if ( FAILED(rc) ) return 3;
$ Y: T. i, N7 L3 o, S- u  U! C7 a( H! A" K! D2 O# B  h9 j
        /* ---------------------------------------*/
5 G' a: K+ {- m        /* 3. Retrieves children under the root   */
% U/ s  {& P: G1 ]: f: k! B        /* ---------------------------------------*/: h  G/ k5 |! ?: G. b
       
4 O& y/ e# P( F        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;
' A0 T/ D8 O- R6 `. }$ r        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;; D) @+ r$ d7 R* e
       
0 G2 Z& V! J" Q, X        // then on a root product, get all the children agregated to it.9 l1 Y) ?2 T7 c3 @- ]: m" E
        CATListValCATBaseUnknown_var*   ListChildren =- A8 _6 \3 z! K5 c+ c2 r' S
                piProductOnRoot->GetAllChildren();! b5 T/ @8 W. ^6 Z% e7 }' Y6 V2 p) N7 ?
/** @anchor err_2 piProductOnRoot not set to NULL after release */
  C; h- v% y8 i3 G( H+ G0 |        piProductOnRoot -> Release();
. |4 g- I0 p4 M5 x$ l! z0 P$ P        piProductOnRoot = NULL;
. x; w. m% `6 w" A) X* z% v        if(NULL != ListChildren): q% H2 |+ I# o* `. `* z( I
        {
( f& M$ m3 C/ h                & ?9 v" w' X8 P1 M5 A
                int numberOfChildren = ListChildren->Size();8 e" U5 f9 V6 e9 \9 x" K4 L
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;6 U, l, U( _; V+ F. A

) o" f8 [' R" C3 g& W9 ?0 T) i7 V                /* -----------------------------------------------------------*/! u8 f: J9 ]$ I! V' D  l& Z1 `
                /*  4. For each child, get its partNumber, and InstanceName   */0 a1 R3 y. @1 K+ a
                /* -----------------------------------------------------------*/$ V% _1 e# p' l& J
                CATIProduct_var spChild = NULL_var;# y! a5 \( d, [7 i- o
                for (int i=1;i<=numberOfChildren;i++)+ C5 U% q9 ^1 ?0 Q
                {
: P4 r/ d$ R3 B/ \                        spChild = (*ListChildren);) Y2 x, o5 r6 g) Y
/** @anchor err_3 spChild not tested before use ( if !! ) */ 9 u: X% n& c, E! h5 V6 f+ Z$ g: F
                        if ( NULL_var == spChild ) return 4;
3 K! g7 B4 e9 ]                        CATUnicodeString partNumber = spChild -> GetPartNumber();
7 o8 e: h" F: I2 m8 |/ i+ P                        CATUnicodeString instanceName (" ");
* n( `7 E( q' s! Y. a  P$ y. z9 t                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;# r. A1 `  x) b" C0 w
                        if  ( FAILED(rc) ) return 4;
& j! L  B. j9 |3 v; j: `+ G                        + E+ v9 J. }" L# C$ P* q
                        cout << " child number : " << i << endl << flush;& t. P( k" u5 G+ y$ e/ X& |1 q
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
' u% K" w5 q. |! W                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
$ L7 u% K% J$ K% ^# w, N$ c                }
- {  R. K, R# }+ m, a5 i                delete ListChildren;
) S" @+ F/ O! Y4 y* ~$ o3 J0 S                ListChildren=NULL;
% I3 L1 b$ R! t9 w% b        }       
9 W6 S8 H. L! T) _: f        /* -------------------------------------------- */
& g* b% a2 t# p4 C( [+ ~        /*   Ends the session                        */
. ]$ i4 \, a3 \  k        /* -------------------------------------------- */[/mw_shl_code]
6 l, M/ K  d! Q+ n) P& c) G4 _
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了