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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
3 C6 _/ r0 j0 w8 Z9 u$ M5 b4 ^7 n" r
Catia二次开发源码分享: 获取装配所有组件列表
7 U8 E% V. f- I
! [$ {$ T! k+ W4 e7 G+ C0 d  C# C% u$ z6 T( s9 \, G
[mw_shl_code=c,true]/* ----------------------------*/
8 t; W  s; }* W$ }7 S5 c  }8 H7 o        /* 2. Retrieves Root Product   */* Q4 M% R* Y/ D. T$ C5 W
        /* ----------------------------*/. E( O5 ~; j/ D3 x$ Z
       
5 e: _6 \. B( ^$ i$ M        // Begin navigation throUGh the document => start with the RootProduct.6 j4 q- e" d5 O4 ]
        CATIDocRoots* piDocRootsOnDoc = NULL;
, {- }1 q* G0 r, Z        rc = pDoc->QueryInterface(IID_CATIDocRoots,
7 v8 g, h* G+ ^9 ~& w                                      (void**) &piDocRootsOnDoc);
+ d$ Y6 A' M  N9 M$ h        if ( FAILED(rc) ) return 3;! x. Y0 I4 K" E" e8 T4 |$ s% H
       
- T: a& ?0 Z7 Z6 a; E# O- x        // get the root product which is the first element of root elements
$ e: T" T" T6 J* N' X0 U        CATListValCATBaseUnknown_var* pRootProducts =
/ i/ u! M1 G+ U1 P                piDocRootsOnDoc->GiveDocRoots();
- A7 h3 A+ F4 I$ S- c7 L: b        CATIProduct_var spRootProduct = NULL_var;' S, v0 P8 Z% _, I
       
$ n3 `: f& U" @5 L9 C, m0 k/ E        if (pRootProducts && pRootProducts->Size())( {0 m' L$ [" l, z% g
        {  ) S+ s2 f/ g4 ~+ i% F, r
                spRootProduct = (*pRootProducts)[1];7 F: z& n6 l6 N1 x" I
                delete pRootProducts;3 e0 u4 h/ V1 W) Y# s0 c+ h
                pRootProducts = NULL;
9 F# l! I. @% [! d) X        }* J9 g* B2 L6 F+ B) M1 t" j* w! a
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ & i! w& L) [7 S1 q  f# [$ F
        piDocRootsOnDoc->Release();. g/ Q; |! b8 S/ ?2 J. Z( @
        piDocRootsOnDoc = NULL;
. G9 z4 B' H' L: C       
, q. b# g3 t, d6 q        // Get CATIProduct handle on the root product.
- `: T  j1 V4 ?7 i6 U7 [1 L        CATIProduct *piProductOnRoot = NULL;
6 X$ ]' y+ l+ k/ p4 d1 Q        rc = spRootProduct->QueryInterface(IID_CATIProduct,* |3 i: q. P9 W5 f* y2 Q2 c+ K2 U
                                               (void**) &piProductOnRoot);
' ]8 T* h6 |. K' m        if ( FAILED(rc) ) return 3;8 r& W, z; N& t6 t1 o3 L

7 ]4 g' G. c, y" \; t% I' z        /* ---------------------------------------*/2 L' f9 O: K3 F' a
        /* 3. Retrieves children under the root   */' x. W5 P2 r2 X0 {; K6 S8 o
        /* ---------------------------------------*/
/ j9 M& V# L0 ^/ P       
, F2 y" i: f2 ], r# o        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;) u* b5 @5 J0 q9 B1 P. o6 Z
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
) t) r  m' s' x; \2 q9 w; _/ H% m9 w        ( g* A3 W  j6 ^+ Q8 t
        // then on a root product, get all the children agregated to it.3 W3 x% M5 T. b/ E7 n
        CATListValCATBaseUnknown_var*   ListChildren =! w0 n% M# t- H
                piProductOnRoot->GetAllChildren();2 b* N# v9 D$ g
/** @anchor err_2 piProductOnRoot not set to NULL after release */
$ O4 G) D9 k3 B" H- V7 _        piProductOnRoot -> Release();# V% ^# ?& a) }7 W/ e# n) b
        piProductOnRoot = NULL;
# B/ m1 O1 c  _3 T) q" n        if(NULL != ListChildren)
8 Q2 s! T. t% T: |! [% Z        {3 g# A# l( i, g; }! U' Y0 E  s7 [# W
               
( I) X; p# v( Z! O                int numberOfChildren = ListChildren->Size();
6 W% L% L( Q) w- c) y, [                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
; c' `4 a( ?1 b" X1 Y! ]8 X5 r' V; W  X# a$ F% G3 ~
                /* -----------------------------------------------------------*/
& K. X% T/ s1 L/ f5 ]4 u                /*  4. For each child, get its partNumber, and InstanceName   */: N3 i, b, I( e' Y
                /* -----------------------------------------------------------*/
5 [) a; w6 m! ]+ T, }                CATIProduct_var spChild = NULL_var;
+ j' S: ^2 e$ f' t) s                for (int i=1;i<=numberOfChildren;i++)7 s3 d6 q/ s$ V4 k4 h4 V. |1 F* J
                {
4 q# g7 W3 X- V0 x, u; q4 d                        spChild = (*ListChildren);' i8 l( e' e9 |- d" S! y
/** @anchor err_3 spChild not tested before use ( if !! ) */
; x% v- R" h/ v0 y& U8 ]6 V                        if ( NULL_var == spChild ) return 4;; S$ S0 o6 z3 M5 t. f+ ^  {
                        CATUnicodeString partNumber = spChild -> GetPartNumber();
- k" ^2 j/ D& C8 ?5 `* V$ f                        CATUnicodeString instanceName (" ");. i9 T3 e) o  e
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;: }) O: J) Z+ h, j- n- Z; X! G' m
                        if  ( FAILED(rc) ) return 4;' P/ B* Z* @4 S  n# S
                        6 |. y8 [6 Y8 {) E7 a
                        cout << " child number : " << i << endl << flush;
* |0 a5 c: u' j* |, W" H" o4 C                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
. I* ]  }" T6 D5 n& ?7 ^$ X3 `                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
$ h. }0 }' e$ V+ }  @6 N- y) ~                }. [/ |0 p3 d9 }% ~+ r; S, r
                delete ListChildren;
9 `1 F8 H+ x3 p5 k( A                ListChildren=NULL;
) H6 ]4 p! {4 O  d  R, K  E        }       
" G0 H6 Y) g; C2 u        /* -------------------------------------------- */& S' C+ M7 I1 k  m
        /*   Ends the session                        */
5 j0 P. L; l+ _- J" P! ]5 |        /* -------------------------------------------- */[/mw_shl_code]1 X1 W7 c# P6 P9 x; B, m( ~
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了