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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
4 `$ A- d, k7 F2 X
Catia二次开发源码分享: 获取装配所有组件列表
2 K, [1 K9 X; `( v% {( Q* a( n; y! f) W
2 b9 t$ u8 t- d+ M. d5 }
[mw_shl_code=c,true]/* ----------------------------*/) l8 w# F: W4 O8 c4 ]) ^. T
        /* 2. Retrieves Root Product   */- a6 Z1 K) z, k* T$ _/ T
        /* ----------------------------*/3 I2 J" \5 m: X4 y& `
       
2 S9 \. E- m3 B6 H5 G; x2 a0 T        // Begin navigation throUGh the document => start with the RootProduct.8 e' p1 ]- f' o; [
        CATIDocRoots* piDocRootsOnDoc = NULL;
1 r4 k3 S; w, y3 Z' a6 C        rc = pDoc->QueryInterface(IID_CATIDocRoots,
$ L. k; c6 z+ n' X* i4 p7 Y' ]                                      (void**) &piDocRootsOnDoc);( Q& V. s- @) T8 e
        if ( FAILED(rc) ) return 3;9 _) R' ~' B' U/ x4 V
        6 f: w! r( L7 ]( b
        // get the root product which is the first element of root elements. @; h1 x/ L) f4 T& b- O
        CATListValCATBaseUnknown_var* pRootProducts =
0 P8 t# x( q9 O6 u- P                piDocRootsOnDoc->GiveDocRoots();
+ T+ h2 p; k6 b5 F: n        CATIProduct_var spRootProduct = NULL_var;' [  a; L9 i' H9 l8 x* `
        ; }+ d+ P8 X2 y3 w% V4 S; r
        if (pRootProducts && pRootProducts->Size())6 t, C7 z# T8 m" x% H, C4 N0 m
        {  2 D7 H- {$ f* b/ h
                spRootProduct = (*pRootProducts)[1];# W2 N0 ?$ d, c1 g& r5 y5 d9 w7 v8 ?/ o
                delete pRootProducts;3 Z: j) ?' I- \3 s
                pRootProducts = NULL;
! D7 d: f& i% u        }# e7 y/ A9 d) W8 O: u- t/ c
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
' i% i4 D( f" B' f" u        piDocRootsOnDoc->Release();+ E% B$ o( S9 J1 q
        piDocRootsOnDoc = NULL;
3 p) N8 E- `" F5 `        - j% O( e5 Q) u
        // Get CATIProduct handle on the root product.% k; W( }1 ?; Y( ]# @: Y
        CATIProduct *piProductOnRoot = NULL;
: |0 ~- m& U, g* b( v, Z% h- F8 o        rc = spRootProduct->QueryInterface(IID_CATIProduct,) u9 k+ {+ A: ]% V; n6 G
                                               (void**) &piProductOnRoot);
5 ~% I! a7 q0 f8 e3 F        if ( FAILED(rc) ) return 3;7 ?% y* n1 F4 g' [' t# E# g6 {4 G, f

+ M. m6 J  T- L9 _, z        /* ---------------------------------------*/
$ x( |& [: _+ y, Q" p        /* 3. Retrieves children under the root   */
8 o3 I$ _' W" K, Q        /* ---------------------------------------*/
2 A4 |2 N. y, X# i        # K" i3 G' b) L. X* a& |- `
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;. _. }: z5 P) O8 W
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;, w, U9 U/ y/ s# ~3 W  h, C8 p
       
+ }1 ?; O: K) d/ i        // then on a root product, get all the children agregated to it.
4 Y: @. \. @( d9 z' _0 l2 |. r        CATListValCATBaseUnknown_var*   ListChildren =
% i* o% m9 j+ N$ O                piProductOnRoot->GetAllChildren();0 {! R1 f; P1 B1 z! s0 H% x9 _3 W
/** @anchor err_2 piProductOnRoot not set to NULL after release */
6 l1 X& G* A- Q2 J3 w4 _  S- C        piProductOnRoot -> Release();
: C( A. e( N, o. T        piProductOnRoot = NULL;$ S8 d4 F0 t; r- K% z# B+ O7 ]
        if(NULL != ListChildren)
8 u/ C: I1 Q9 C        {
* m% V9 c* ~; J- r, d               
$ g* Z7 o. a- F$ P( B% l                int numberOfChildren = ListChildren->Size();5 ^4 Z. _& w7 s
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
' F6 @- |5 U1 [2 O) s) r/ g: y$ Y  f* Y
                /* -----------------------------------------------------------*/2 [# L% M$ H% B4 a% I% ?; k. A1 i
                /*  4. For each child, get its partNumber, and InstanceName   */
1 s5 U3 O" _! Y1 U6 T+ k- H/ |% F                /* -----------------------------------------------------------*/) ?! D( X+ m! |6 G, d. B9 J
                CATIProduct_var spChild = NULL_var;- o  r- }+ I- p7 H) K% Z
                for (int i=1;i<=numberOfChildren;i++)0 }  w& `. E) M" V8 T2 j' R
                {+ ~2 O" [& o: t9 ~4 b) |# \+ F
                        spChild = (*ListChildren);9 H2 B+ p: Z, z! M% R# H
/** @anchor err_3 spChild not tested before use ( if !! ) */ 9 ~2 v3 B, L! n+ M/ D* g4 c* Y
                        if ( NULL_var == spChild ) return 4;, }6 x  e( u& q6 t+ V
                        CATUnicodeString partNumber = spChild -> GetPartNumber();0 o) t* \% }9 E6 T& G. I/ e) V$ D
                        CATUnicodeString instanceName (" ");, z- T: _" G$ J" i& x. D& j6 n1 y
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;0 F! n: G; _- V; P- v/ B- M0 [
                        if  ( FAILED(rc) ) return 4;! s  e8 W8 n2 y2 Y' U
                        % F  i) Q* q/ L2 ~. @' r2 R
                        cout << " child number : " << i << endl << flush;
8 E, W! v8 a) u  A# E! R                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
+ }! y2 i2 k7 m0 U2 K                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
' o* `! w8 a0 i* J# \( i                }
; Q6 b* F( p; ]& j4 Y# }                delete ListChildren;
! b, F  n! q2 J4 H& u9 w5 N3 M0 @" E                ListChildren=NULL;3 n* c% j. [( h: f2 T% Z: p0 l
        }       
' L+ e: Q9 w. B5 r$ [, z. T        /* -------------------------------------------- */
6 R8 O) k0 z+ b& I        /*   Ends the session                        */
- @* p' s' R. a        /* -------------------------------------------- */[/mw_shl_code]; [. w+ s* ]! 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二次开发专题模块培训报名开始啦

    我知道了