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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
8 ~+ v& U; z2 a: W5 m8 F/ R& d8 p
Catia二次开发源码分享: 获取装配所有组件列表6 U+ I  }3 J  D5 Z- h7 ^) L3 s

4 |( D! M3 C, `: L9 n4 A( G, \9 I; r
[mw_shl_code=c,true]/* ----------------------------*/
5 b  @4 x4 [  \1 l9 }        /* 2. Retrieves Root Product   */) o( m8 ~% `' e4 f8 c* L
        /* ----------------------------*/1 A9 i' K8 `1 K9 d7 ]- q7 b
        6 R) f! H1 P  [# b; H9 \
        // Begin navigation throUGh the document => start with the RootProduct.
! y- d* U2 ]$ O- r* K1 O6 _( h0 s        CATIDocRoots* piDocRootsOnDoc = NULL;
/ l  X( b) p1 D        rc = pDoc->QueryInterface(IID_CATIDocRoots,
8 J- I( o6 m9 p/ b                                      (void**) &piDocRootsOnDoc);6 G4 b' w( q  ]. v6 i7 J
        if ( FAILED(rc) ) return 3;6 E! l( F6 X! T9 q% O
        + k: l6 c  u- @8 @0 Z$ ?
        // get the root product which is the first element of root elements4 A$ g  Y0 U* T4 @3 `9 ]( z
        CATListValCATBaseUnknown_var* pRootProducts =   E# x" F/ D" @8 F8 x
                piDocRootsOnDoc->GiveDocRoots();2 d' X! k6 @$ C( ~* v: ^' M: d$ ^
        CATIProduct_var spRootProduct = NULL_var;
& K" k: X2 z/ w       
3 v2 c" H2 k( [& v& @        if (pRootProducts && pRootProducts->Size())
" K8 L" A! C% @' z& x        {  2 Z5 O- u+ Y/ L  n1 m$ P/ ]% ~
                spRootProduct = (*pRootProducts)[1];0 X. @$ P1 q  y& H7 j9 U
                delete pRootProducts;( `  s/ ]0 j, f: ?# f
                pRootProducts = NULL;
( E5 K- B9 v1 Z        }
' k4 X/ V: |; u& l/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
0 `+ n; r; _$ q+ z/ F0 ]        piDocRootsOnDoc->Release();4 }7 G3 [- x& G1 @3 I: T
        piDocRootsOnDoc = NULL;3 J) G" Z1 ]9 y1 M
        ( C4 }. P2 a3 Y$ C; `* N
        // Get CATIProduct handle on the root product.
* d  D0 t: L, `/ @4 ^! p        CATIProduct *piProductOnRoot = NULL;' C: S: J2 Y" i( N) p- B" R
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
! F; Q# e( `9 }2 U6 l. a6 z1 ^: N0 {                                               (void**) &piProductOnRoot);( y% e3 z7 G4 y8 C9 K: T+ g
        if ( FAILED(rc) ) return 3;& l. k9 |# ?. |3 X, q, ]
" q, i! a2 k1 i; O% r% |( F( X
        /* ---------------------------------------*/( ?/ m# H: l9 [# Q5 ~
        /* 3. Retrieves children under the root   */- w) v8 ]0 X& S9 o
        /* ---------------------------------------*/
1 g7 T8 X) a! V5 c6 y4 J       
/ Y  @, C  Y* U6 y% i        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;0 B0 Z! J7 b5 k$ X! v. }5 r
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
& I& N- [' K; c0 v        0 x& f7 Z. g: h3 O
        // then on a root product, get all the children agregated to it.5 ?% F: [4 W) c! o0 N
        CATListValCATBaseUnknown_var*   ListChildren =# H) e2 }  G' f' D: z  Q
                piProductOnRoot->GetAllChildren();& c0 F! M/ f+ l
/** @anchor err_2 piProductOnRoot not set to NULL after release */ % |3 u1 b$ \" P
        piProductOnRoot -> Release();
! W  B% c/ x. z8 U8 \        piProductOnRoot = NULL;
; e' E! F4 }7 Z5 B6 S3 z        if(NULL != ListChildren)( B4 k4 o* L4 F  p# E
        {% i* S3 S6 S2 K' C: S
                6 v1 G( m# [. K+ w. F
                int numberOfChildren = ListChildren->Size();5 ^/ o8 h+ u: o. n) E
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
6 {6 K2 W% x' [  Y; b& f/ }
" ]% m; g8 b1 B% z% c; d( C5 S                /* -----------------------------------------------------------*/2 e# w) w6 g0 ~+ a* C5 n
                /*  4. For each child, get its partNumber, and InstanceName   */! U3 {. q9 l% j7 N
                /* -----------------------------------------------------------*/
5 R. D1 i, {# u% r                CATIProduct_var spChild = NULL_var;
( r  P4 e$ ^- l                for (int i=1;i<=numberOfChildren;i++)
* d, k% R8 C4 j0 O' z6 w$ P7 R                {. @, A0 U, k  q% \3 j
                        spChild = (*ListChildren);0 ~. U9 S) v+ u4 O; M3 j. c7 e
/** @anchor err_3 spChild not tested before use ( if !! ) */
* y0 b- `* o$ ^$ N; B* L6 Y                        if ( NULL_var == spChild ) return 4;
. g, P' L( L0 p) h5 }                        CATUnicodeString partNumber = spChild -> GetPartNumber();
3 ~; x9 L+ I1 |  a                        CATUnicodeString instanceName (" ");/ L9 ~( p3 I" T8 @1 n% b
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;  s; _% a0 A! }7 U2 T5 _. Q
                        if  ( FAILED(rc) ) return 4;; Y5 q2 D! v, x/ r! ^! B$ J( g! i
                       
$ P+ |: E' t3 j& O( Q                        cout << " child number : " << i << endl << flush;
0 n) b8 a( Y% D# H0 \9 ?                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;! L/ t  @1 X5 }; g
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;. b# a$ I" r8 Y7 _
                }: D) E  ~. \4 G8 r* ^
                delete ListChildren;
# {# x+ b+ }6 h' T8 b% \5 p                ListChildren=NULL;6 z, H! \  @4 G$ O9 H7 H% \1 T
        }       
  _9 Q' n. v* F! C7 h$ s        /* -------------------------------------------- */* X/ B5 |! ?# Y3 }( G" z  U; T8 d
        /*   Ends the session                        */
$ E7 A+ l) Y7 G6 |        /* -------------------------------------------- */[/mw_shl_code]
; d" g8 t; e; o* V
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了