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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

$ G- K8 I) S6 t8 p) W2 nCatia二次开发源码分享: 获取装配所有组件列表' H; z/ G: b  C

% a: Y; n$ g! y0 B' |2 a. {/ O' u/ H2 H9 ~
[mw_shl_code=c,true]/* ----------------------------*/
2 m. s$ X) Q+ T) |. J- i        /* 2. Retrieves Root Product   */4 o2 P7 ]' o' N1 t# }+ V+ _# E
        /* ----------------------------*/
( j% D! J# I" m# R/ f' A        & T7 v2 d$ g  S
        // Begin navigation throUGh the document => start with the RootProduct.
7 V5 o/ k. B' N! n) Y- h5 {        CATIDocRoots* piDocRootsOnDoc = NULL;
) y" M% h* D$ F9 E% c/ z0 x( n- L        rc = pDoc->QueryInterface(IID_CATIDocRoots,, _! K. C3 _* U0 b9 r
                                      (void**) &piDocRootsOnDoc);
: U- T+ \2 q; O  t( E- M        if ( FAILED(rc) ) return 3;
1 D# G4 @3 ]/ S1 g        6 p) P% a7 K  A; M" ~
        // get the root product which is the first element of root elements3 F/ p9 A! `' _/ f) t1 R; r# k+ E
        CATListValCATBaseUnknown_var* pRootProducts =
5 A' c7 |" E2 x/ f/ P. Q                piDocRootsOnDoc->GiveDocRoots();
8 t6 V% z- K7 q. z& O) Y/ |8 k* C        CATIProduct_var spRootProduct = NULL_var;, `0 n/ T; L. C: U! J1 {+ O% t* X* I3 U
       
/ a7 \$ s# ^7 }5 m" ~' u        if (pRootProducts && pRootProducts->Size())1 N7 h$ W* M) z3 Y$ C, [; L
        {  $ a/ V  }! f: Z% h
                spRootProduct = (*pRootProducts)[1];
9 s, ~0 S3 d+ N/ N- R5 E3 k3 b                delete pRootProducts;  s* X0 [0 g: i0 {, z
                pRootProducts = NULL;8 U! T$ V' L7 Q& i  x% m+ x
        }
/ o1 k9 v$ D# p/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
4 u6 V+ ]: i2 w4 d        piDocRootsOnDoc->Release();
0 V( A! E8 P9 X9 `6 z        piDocRootsOnDoc = NULL;3 H4 ^( ^/ E7 v8 l
        # k0 g( \  s' S
        // Get CATIProduct handle on the root product.* n$ w- n& d/ E; _
        CATIProduct *piProductOnRoot = NULL;
; Q: B7 @' [" `        rc = spRootProduct->QueryInterface(IID_CATIProduct,0 t0 k& u" }7 k$ N% R
                                               (void**) &piProductOnRoot);
# [( q! I  p( Y  {# c8 G) |        if ( FAILED(rc) ) return 3;% `: y  N0 T, _7 G( V7 ?" I8 N5 p
; D0 R0 H$ b  n8 {+ f
        /* ---------------------------------------*/% @# ]! ]  E& P
        /* 3. Retrieves children under the root   */
4 |2 r9 w8 Q; w0 D  G3 [. u% b        /* ---------------------------------------*/
6 \+ _$ `/ l2 w3 {- a  a" P        $ D$ q" G* g  d; V6 j
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;  T' i. I; D  n+ M7 Z0 j1 U
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;1 C5 ]/ w9 W5 w  r# i6 u# A1 b
        5 i+ T! [0 u1 w
        // then on a root product, get all the children agregated to it.3 C# B' h( r6 P
        CATListValCATBaseUnknown_var*   ListChildren =
2 ~! u/ w  `+ l' E7 N6 p                piProductOnRoot->GetAllChildren();
3 P7 O. W5 w# W1 z# i/** @anchor err_2 piProductOnRoot not set to NULL after release */
; z8 v8 {; `8 S  @" x) L* l1 v) J        piProductOnRoot -> Release();
. N& i, m/ U+ y        piProductOnRoot = NULL;
0 W6 E; B2 X  J) M        if(NULL != ListChildren)& ]: n4 J' e" E9 E, k: N$ C
        {
' _0 l% x0 _/ H+ c/ J               
8 j3 W/ D7 O. G) n/ Q/ x                int numberOfChildren = ListChildren->Size();7 `6 i; ^$ w0 p- H9 {
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
9 P: }, y2 I$ W9 |
5 K6 L  k- x9 H! V                /* -----------------------------------------------------------*/
: Z- Z0 Z8 U- A- t0 R  [0 W2 v                /*  4. For each child, get its partNumber, and InstanceName   */
4 J' d" a0 o$ ~0 q7 z, m                /* -----------------------------------------------------------*/
/ \' q9 V- t3 ^                CATIProduct_var spChild = NULL_var;- |/ E( s# k6 I: @8 V% h
                for (int i=1;i<=numberOfChildren;i++)
3 x. T6 ]. O8 r, ~& [* l                {  W+ n/ i  t# h+ @5 Y0 Z$ Z6 L# B" T
                        spChild = (*ListChildren);
; m* g7 y2 s5 F: \- [( z/** @anchor err_3 spChild not tested before use ( if !! ) */
: v- R  i9 k5 j                        if ( NULL_var == spChild ) return 4;
6 t- P% o- z- p$ |' x) S/ s                        CATUnicodeString partNumber = spChild -> GetPartNumber();0 ]" h: f0 O" ]7 b) n, ?
                        CATUnicodeString instanceName (" ");
( `& q2 N& F( f9 a, C( \( n9 }                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
8 T. `* x$ G  {- C/ |+ X                        if  ( FAILED(rc) ) return 4;" B: |, ~2 M4 n
                        ' L9 F3 B) ^6 _+ \4 L$ ~$ O
                        cout << " child number : " << i << endl << flush;
/ s6 q3 p9 A5 h+ X+ H                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
$ N# }% [& t6 Y1 _+ @+ v                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;( r9 J9 n  I, i) e. l  ]5 U( {7 e8 y
                }0 d1 q4 D! A+ ~$ c. U
                delete ListChildren;9 X7 h4 Z3 h$ @2 C
                ListChildren=NULL;
9 j/ e: Y- \& [        }        - }5 r% y9 H$ S
        /* -------------------------------------------- */+ L1 V; E- S. E4 d5 l' L: Y
        /*   Ends the session                        */8 L: ?5 k8 S  ~
        /* -------------------------------------------- */[/mw_shl_code]
" I4 D4 S7 Y" T  u# l1 F! J
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了