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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

- k5 {2 O# Z4 X! v. A& qCatia二次开发源码分享: 获取装配所有组件列表0 p; i2 i/ F& ~6 X5 x0 `9 H

5 P6 t7 W& U, t5 G. p- x; H/ ~6 S; O; b2 R' l: V) M. A4 I/ e
[mw_shl_code=c,true]/* ----------------------------*/4 ^. t6 ]% ~1 u' i1 {
        /* 2. Retrieves Root Product   */( W4 J/ Z$ j& l4 z! \
        /* ----------------------------*/
: B5 T. F2 |: ~* C5 S2 u- d9 y        6 P3 C- c, G) h" B9 V
        // Begin navigation throUGh the document => start with the RootProduct.
" e7 T: X6 D: D5 G; I/ E+ M  b, L        CATIDocRoots* piDocRootsOnDoc = NULL;( _3 w7 Y3 ~. M  ^& h
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
' H9 X: N. f+ ^  o                                      (void**) &piDocRootsOnDoc);
: y6 X/ g1 @# Z0 O' \        if ( FAILED(rc) ) return 3;
* l' s3 r6 B" ~* Z; y       
4 F; e" e1 z9 E7 t- p        // get the root product which is the first element of root elements8 J* q+ D5 q" J
        CATListValCATBaseUnknown_var* pRootProducts = 1 S: G6 u' O- n1 e) V( ^; z
                piDocRootsOnDoc->GiveDocRoots();
  J; U5 d! R8 c/ @        CATIProduct_var spRootProduct = NULL_var;
+ g. O& Z- @  ?8 ^+ V/ {+ M       
: v4 ^$ t5 B' n) U2 b) ?' B        if (pRootProducts && pRootProducts->Size())4 y: ^* E3 }: {" ]7 P( C# G* A1 E
        {  9 z: L; R; D. N' Z0 r9 H
                spRootProduct = (*pRootProducts)[1];4 k5 P! |4 T/ j; f
                delete pRootProducts;' ?4 _$ M! h4 y' s' H. Y/ x
                pRootProducts = NULL;- p2 s) i1 Z  V9 ?% h5 y# j9 L
        }& _9 d8 m" C( n7 D- d
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
5 p! X8 v  ?0 v& @        piDocRootsOnDoc->Release();
& S2 G+ }6 S4 [/ ^6 w4 F% x7 Y2 ]        piDocRootsOnDoc = NULL;$ m# C! M1 q! H" v  @
       
" z( o* p: p' C# `8 i) R& i        // Get CATIProduct handle on the root product.1 t$ a$ _+ D! W7 a% b- @
        CATIProduct *piProductOnRoot = NULL;
- d' y8 F/ W  p        rc = spRootProduct->QueryInterface(IID_CATIProduct,
/ w2 k. \' ?  M" d( Z  m                                               (void**) &piProductOnRoot);
2 ^0 e% |. i& D2 |8 B* y# v        if ( FAILED(rc) ) return 3;
) z/ n. b( u9 X- x9 ?6 K' n/ S% F9 J
        /* ---------------------------------------*/( x( D- ]! v0 g' P+ O) ]
        /* 3. Retrieves children under the root   */
; V& L* Q) l3 b$ a2 c, m+ j        /* ---------------------------------------*/5 c$ r2 s! @6 f2 W/ k
        ; Q7 B0 j* \. `% v3 S( L8 {1 E
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;6 m$ y( l  p  ~/ g# V7 a+ P
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;5 S9 I7 Z+ g0 [& L- @$ D( g" @! E
       
9 A+ e/ X3 X0 d: h1 h        // then on a root product, get all the children agregated to it.0 p# p8 e, \. z
        CATListValCATBaseUnknown_var*   ListChildren =
; A" A5 k( j& g! Q3 \                piProductOnRoot->GetAllChildren();  K! ]4 k1 ^5 B
/** @anchor err_2 piProductOnRoot not set to NULL after release */ $ R, M) t# p- S9 n
        piProductOnRoot -> Release();
" a2 a4 o# A) d( M9 C) w        piProductOnRoot = NULL;
9 C1 A4 {% C, F- L5 B        if(NULL != ListChildren)
, d2 T3 {& E" t- p        {
' M6 H4 G. T& ^1 z& s; \  U9 [                % }# z/ V3 _  B0 j4 ]6 Q
                int numberOfChildren = ListChildren->Size();0 A/ P( l; s! b7 u, `1 c
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;/ N/ o- J/ H, _$ P7 g- E6 E+ Q
5 C6 {6 p/ n- z' U# b7 G6 i
                /* -----------------------------------------------------------*/9 U; E3 t& e) t
                /*  4. For each child, get its partNumber, and InstanceName   */
, d8 |5 r# ^0 v' v2 i                /* -----------------------------------------------------------*/9 K8 F) P2 l( p
                CATIProduct_var spChild = NULL_var;0 f9 {# B0 @5 b9 X
                for (int i=1;i<=numberOfChildren;i++)
+ ^5 |# t( E2 I+ M$ r                {- @% o# c9 _6 i9 b
                        spChild = (*ListChildren);
0 D3 n! j/ V: i  t/ E7 Z/** @anchor err_3 spChild not tested before use ( if !! ) */
8 b8 ?- a" U( G+ `- a) e- S/ y6 l# A                        if ( NULL_var == spChild ) return 4;
' n8 z" N- ~3 l. E2 ~                        CATUnicodeString partNumber = spChild -> GetPartNumber();
; Z8 q$ N" m4 D2 O) g/ Z2 g                        CATUnicodeString instanceName (" ");
5 a8 T7 u% X* G/ [# D7 v! [& l' R                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
' x* c/ O* r8 k+ [- s                        if  ( FAILED(rc) ) return 4;
5 l2 E: P  j3 F' M  z/ Q4 w4 d% o                        ' J% ]" ]3 {. |5 Y7 Y
                        cout << " child number : " << i << endl << flush;
9 U0 b0 ^" _' p: M$ ^                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;- x3 s5 S+ O  R' I/ |; a( q
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;4 w- Q( L- T2 ^- N4 k
                }
5 [9 m" g3 f1 E. l! L                delete ListChildren;5 ]; P5 G: E; m7 |: ]% g4 r0 J3 N' e6 k
                ListChildren=NULL;
, m$ E& y" T0 C* H        }        0 h/ O0 u! N3 w# I5 k
        /* -------------------------------------------- */
5 t( Z" ?! ]# S$ j: ]2 Q6 f! V        /*   Ends the session                        */
: e1 u+ R4 [9 k0 Q( f. @        /* -------------------------------------------- */[/mw_shl_code]/ }; e4 [. n5 j  I& O' ]1 z& ]2 p8 p
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了