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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

  ~9 Z1 c, A; P9 a( `- q# }+ }Catia二次开发源码分享: 获取装配所有组件列表+ L9 ?# }% j+ X0 _& p
- i' O7 I/ S/ q3 ?7 f1 y5 u* m* Z# h
) c9 D# ]$ s% m, t8 q# W" {% a/ U
[mw_shl_code=c,true]/* ----------------------------*/; @+ s+ q4 z* B+ S* c) V
        /* 2. Retrieves Root Product   */
" x; J) Z7 S! y) a1 E        /* ----------------------------*/
4 L% L& U8 t8 a/ F& u       
) n) Y% G1 L# W+ A        // Begin navigation throUGh the document => start with the RootProduct.6 m: V, [- H0 ^, _+ K' ~2 q4 y
        CATIDocRoots* piDocRootsOnDoc = NULL;6 Z6 S" ]3 |, n# U; d: N* p
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
# Z9 A. ?- R6 S: D                                      (void**) &piDocRootsOnDoc);4 d& ?% z3 L3 `' s% x- t
        if ( FAILED(rc) ) return 3;
: x' V2 Q& j4 f: C       
: q% v, v' z3 f: x. B3 u        // get the root product which is the first element of root elements
; O8 S: s% e: K$ @0 t        CATListValCATBaseUnknown_var* pRootProducts =
3 [5 G7 g2 ^+ p3 D; J                piDocRootsOnDoc->GiveDocRoots();
9 X5 C! E/ |# g" i* X        CATIProduct_var spRootProduct = NULL_var;
: Z$ P1 h, g6 V2 @+ b8 t8 n        - z0 o! `- R: H1 u+ ~
        if (pRootProducts && pRootProducts->Size())
: o9 k  [1 m" g        {  - \! h. T5 f. a) J
                spRootProduct = (*pRootProducts)[1];
1 H% W# O4 L1 {. c. Y, W- \/ X                delete pRootProducts;; C6 s2 W: `4 z( V. Z6 @
                pRootProducts = NULL;
' ]8 B: t8 j8 N# k9 o' Z+ `4 }, r        }, T5 [6 `1 Y6 p0 f
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ 3 P: d- Q- G2 ?, O
        piDocRootsOnDoc->Release();
4 [8 I' }7 R9 I4 k+ F- A( \        piDocRootsOnDoc = NULL;4 R( ?- d2 d3 C. n5 p9 i" F
       
+ W* A+ Q. Q' e6 o* d3 I$ p+ d( v        // Get CATIProduct handle on the root product.
/ \2 S: \1 A7 L8 u' P( ^        CATIProduct *piProductOnRoot = NULL;
6 R+ Q" L; E- B        rc = spRootProduct->QueryInterface(IID_CATIProduct,
( |! z! A" h+ v5 p- |: S5 l                                               (void**) &piProductOnRoot);
8 M+ C5 w2 \2 |+ Y        if ( FAILED(rc) ) return 3;
: n( e1 b0 g% k8 C* L' B- X( v0 c- ]: B
2 i3 g# i1 \* b; a9 _& p9 }9 p) |        /* ---------------------------------------*/
; ~9 R# E* ?# G  e        /* 3. Retrieves children under the root   */- Y) o6 g; G0 K3 g
        /* ---------------------------------------*/- a. C/ w9 ~& K! Z5 h$ \
       
' b- ?' r3 s; I2 o2 O) n4 F        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;4 a1 }# Y  F) x8 a: B7 x
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
0 x. x' ^& B; _( a       
. V; f6 z% \& d% w& `& ]        // then on a root product, get all the children agregated to it.
5 m9 \/ ^9 g8 }: e! W& t        CATListValCATBaseUnknown_var*   ListChildren =
0 r2 Q( C" ^# z                piProductOnRoot->GetAllChildren();# Y2 ~7 W2 h9 l% w% K
/** @anchor err_2 piProductOnRoot not set to NULL after release */
# k/ t8 e( ?( c+ L3 ^" t        piProductOnRoot -> Release();
3 o; B8 Z9 i$ q3 i) c0 ]        piProductOnRoot = NULL;4 R8 u3 A0 q9 N: ^4 R* M/ [+ G
        if(NULL != ListChildren)
/ g; R3 p3 e( t  O5 y) r) r3 G0 R8 T        {5 O' e  g  b; \8 ?9 ^0 {1 z
                  B+ |7 H; b; A- S& A
                int numberOfChildren = ListChildren->Size();
" N" ]0 U/ i0 L6 X                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;' N1 ^1 D! `3 h# I

7 g- y4 k1 D! m# X! |% V/ @                /* -----------------------------------------------------------*/* R6 ]; V% u/ G5 t/ j/ j1 w
                /*  4. For each child, get its partNumber, and InstanceName   */
5 z* j& h& r' n, Z                /* -----------------------------------------------------------*/+ r+ u! L* u( L  W
                CATIProduct_var spChild = NULL_var;
8 l. g0 c& l$ C, p$ q% E9 [                for (int i=1;i<=numberOfChildren;i++)+ b8 y' l$ Q) x' P- \- R" A
                {
! c$ _1 J' }3 E1 X8 d                        spChild = (*ListChildren);/ P$ ]! }9 O) a! P' G2 M" x% _! J
/** @anchor err_3 spChild not tested before use ( if !! ) */
# ]8 B5 O# E$ [7 R9 [7 P                        if ( NULL_var == spChild ) return 4;0 {1 S. \0 D' o9 v4 A
                        CATUnicodeString partNumber = spChild -> GetPartNumber();3 v% Y( G  ?% q/ O
                        CATUnicodeString instanceName (" ");
' F. f6 E: C5 w$ q                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
& `  Z) e3 T6 m, z3 Y$ {2 r                        if  ( FAILED(rc) ) return 4;
) {; Y5 [; P( ?# U: w( e/ V' F0 B, _                        7 b2 ^6 l8 g0 u' `  C: ~( u
                        cout << " child number : " << i << endl << flush;
5 \& G0 @& }2 U8 M3 H: j- A                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;6 o- _/ U( y, t/ g) |
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
- a1 e# n  z( a0 P6 C) ]                }
7 c7 Y- r# w- t- G5 G: E1 e                delete ListChildren;
4 C) `( C5 X2 H                ListChildren=NULL;
# v/ e& F/ v# f( l( s4 z, x' E        }       
# ?& A( R5 e5 s; Q5 M% N9 N7 B        /* -------------------------------------------- */0 T3 p+ K. i# U& G% g. ?+ s! W
        /*   Ends the session                        */
9 R/ R0 N$ W/ Y, ^8 Q+ N        /* -------------------------------------------- */[/mw_shl_code]
7 o* V! `: t& n; y
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了