PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
' M8 |' B; K, w4 L4 P6 `) v5 i
Catia二次开发源码分享: 获取装配所有组件列表/ B3 Z/ a2 L0 s

2 Y/ Z' U! l5 A, A4 {& O) z1 f: ~2 t' ]
; p0 C1 D6 r0 ]7 e5 E1 K7 U6 G[mw_shl_code=c,true]/* ----------------------------*/- P6 m1 m5 m6 j# B5 ~$ }1 m# P- n
        /* 2. Retrieves Root Product   */
  X! V  Y$ B9 L9 w        /* ----------------------------*/# h8 ~# |- J7 ~  S
        5 I& y" Q6 f2 l  U+ v
        // Begin navigation throUGh the document => start with the RootProduct.
* d2 j* B% I4 d5 Y$ b        CATIDocRoots* piDocRootsOnDoc = NULL;! c5 T; u4 S1 Z9 D: P- k) o4 f$ z
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
$ m- ^  I2 @1 q3 z% \6 U6 m5 j                                      (void**) &piDocRootsOnDoc);
( z4 H) Z8 J; j) b; R        if ( FAILED(rc) ) return 3;" G( I% X% b/ x& S$ D; r+ B
       
/ `* x! X9 R* z. d' z. j; V8 h        // get the root product which is the first element of root elements
) q7 m' t) B6 l2 Z* b        CATListValCATBaseUnknown_var* pRootProducts =
; L: g9 M! A; c+ i                piDocRootsOnDoc->GiveDocRoots();
( ?( z$ S# w: M% N; A$ z        CATIProduct_var spRootProduct = NULL_var;
$ m' ?. }1 E6 u9 U       
. Q3 u; ^3 X. d) I1 ?! s        if (pRootProducts && pRootProducts->Size())9 d3 [; {" @- c1 ~& k
        {  
' s& P8 u# _5 [- G+ [# j                spRootProduct = (*pRootProducts)[1];2 @& o8 x0 [! g- s% O4 U' I
                delete pRootProducts;7 ]& K. `% G2 `$ m% s! R
                pRootProducts = NULL;
6 T7 q3 z  A# _" ^        }; E, @$ Q2 [; n1 [( U
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
7 ?$ v% R8 W( M6 m* i1 K        piDocRootsOnDoc->Release();
0 F7 {, i# j) e        piDocRootsOnDoc = NULL;/ ^- G6 C* l: Q9 b+ L0 d1 Z$ V& S) L
        - B1 a# O4 t+ u3 J
        // Get CATIProduct handle on the root product.
2 z  m2 ^* Y$ r/ X8 N8 J) L% m        CATIProduct *piProductOnRoot = NULL;3 j* ?, P5 T6 v6 ^# q! T4 n
        rc = spRootProduct->QueryInterface(IID_CATIProduct,  [$ }" D% m/ P; Z
                                               (void**) &piProductOnRoot);7 P& X+ r0 |) t/ I( ^- T
        if ( FAILED(rc) ) return 3;0 M9 S9 t! W/ @9 y0 z' [8 E" h7 Q
& W- T* A6 |& e! m
        /* ---------------------------------------*/1 w* V5 X1 B6 `8 y2 q  L
        /* 3. Retrieves children under the root   */4 {; j6 D6 M8 ?7 y+ }% |% o
        /* ---------------------------------------*/1 o9 s4 s+ e  X% i% o& X0 f1 g
        " [! C3 H  T, `6 p) k
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;
' o9 ^- b& w8 g: S/ ]        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
( ~# P8 _8 x, ~' K        & c% t% @  k" ^, y; |3 }) k1 Q+ N+ r
        // then on a root product, get all the children agregated to it., R" c' T1 v. j  I, B! n4 X1 {
        CATListValCATBaseUnknown_var*   ListChildren =
- G. G' ?+ w0 ~8 R$ l6 Y                piProductOnRoot->GetAllChildren();$ D% F- T2 K. ~4 ~2 q, p
/** @anchor err_2 piProductOnRoot not set to NULL after release */
' v" z0 ]( i7 N        piProductOnRoot -> Release();
4 x6 D/ k8 L0 W$ Y0 S        piProductOnRoot = NULL;/ L5 ~0 k$ N5 b& e+ x8 n5 [5 h
        if(NULL != ListChildren)
/ J7 f/ K+ N& n        {
2 s8 \+ f1 O8 }+ N: D" `; d, _               
8 x2 `$ n0 J- S' j" z: [                int numberOfChildren = ListChildren->Size();
& q6 L/ k' t* }4 |  Y. G                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;% e+ R' d  }: z- e& k" K
$ O& v8 e  a$ `& F8 }
                /* -----------------------------------------------------------*/: H! a% {5 n% v
                /*  4. For each child, get its partNumber, and InstanceName   */
5 q" q- g1 u4 H4 E                /* -----------------------------------------------------------*/% O+ _' g. c8 m% F; W
                CATIProduct_var spChild = NULL_var;6 Y0 q& O% j0 S, ]( z7 e$ @" N* @
                for (int i=1;i<=numberOfChildren;i++)
6 U6 F% @! a* u- C! Z5 ^. M                {: Q2 R1 Q0 }4 `- Y1 R
                        spChild = (*ListChildren);/ e& b! |4 p' f
/** @anchor err_3 spChild not tested before use ( if !! ) */
+ R  g* s3 G1 G4 Z) |: b% ]2 J                        if ( NULL_var == spChild ) return 4;
! U& N; J5 l: U6 b7 N                        CATUnicodeString partNumber = spChild -> GetPartNumber();6 b+ y0 [4 L  y0 }
                        CATUnicodeString instanceName (" ");7 r! J" M5 O  M. r( a# M5 }. C
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;" L( J3 L7 c8 P6 ]7 Z3 q
                        if  ( FAILED(rc) ) return 4;+ h% B' J. z0 j) c4 U, n$ `
                       
! V9 Z; i0 C* h' l# F                        cout << " child number : " << i << endl << flush;' `. S9 @  W4 V$ u
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;) G$ L4 i9 r+ F$ V" ^. Q
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;0 i; N9 J6 }" }7 @' I/ Y
                }
0 ^$ c( b" Z; U6 ]$ ~1 F! @% r                delete ListChildren;
5 m9 w6 u1 L/ ]. ~, m7 k, [                ListChildren=NULL;- C4 u  p& F9 E% ]/ j
        }        # x7 v5 A  Q0 w* r8 _
        /* -------------------------------------------- */5 n/ W: j* v( U. L
        /*   Ends the session                        */
. w" f- ]2 r* n" g( f' y        /* -------------------------------------------- */[/mw_shl_code]
- V/ g" h1 p) F5 O1 z0 ~
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了