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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
0 M+ z7 q5 Q: B' ?
Catia二次开发源码分享: 获取装配所有组件列表& j1 H# W# z/ }8 {. m
/ o- H. M; t$ b9 L, {7 m/ o2 ^

+ p  j% S: G* p& b3 e% H[mw_shl_code=c,true]/* ----------------------------*/
$ q$ Z$ G! D* c  t% Y, J- \" s        /* 2. Retrieves Root Product   */$ e' M9 l" e: t8 z% o$ z1 r
        /* ----------------------------*/* ]7 t( \4 t8 ?% p: g# T
       
0 k9 k4 T3 E( g        // Begin navigation throUGh the document => start with the RootProduct.3 t# n# a) U8 L
        CATIDocRoots* piDocRootsOnDoc = NULL;
* Q! s8 A  e5 d. s# x        rc = pDoc->QueryInterface(IID_CATIDocRoots,
3 Z. F& d% S4 m7 O$ ~                                      (void**) &piDocRootsOnDoc);! O+ N, x; ^0 y6 M$ M, F9 C) w
        if ( FAILED(rc) ) return 3;, c( k: l$ B5 U: n9 [' O0 \
       
( [+ I; w% a" l$ w) e: t        // get the root product which is the first element of root elements
" ~1 ^) r" X$ P( M& B& u6 x9 R        CATListValCATBaseUnknown_var* pRootProducts =
! E5 {  L! Z1 v- K* S                piDocRootsOnDoc->GiveDocRoots();
0 ]# c5 @" }4 _  M5 K        CATIProduct_var spRootProduct = NULL_var;
& @( l/ V4 \/ V  h        : s6 t$ K% k* `# K' I  S6 R& n
        if (pRootProducts && pRootProducts->Size()), V# x" G4 q) V4 f4 D
        {  9 Y( Y* d$ J% E# {! U6 }
                spRootProduct = (*pRootProducts)[1];
" w+ t. M; Z3 a1 r& q. }) A3 D                delete pRootProducts;
  N% q9 ~; |' B1 C0 t  G+ k0 ?" S* s                pRootProducts = NULL;
: e9 D6 V% L% ?) a; G$ s        }
/ ^- Z* y  t; Z+ j/ x8 P" m# h/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
% N# V6 T/ v! I$ r3 |        piDocRootsOnDoc->Release();
; I' Y  `6 R' Q/ N: G" ~        piDocRootsOnDoc = NULL;
; f( ~# w/ a7 E0 N, V) p       
2 v/ N, P" V4 E* p# {        // Get CATIProduct handle on the root product.* u1 z& d* O% ]5 d( B) Y/ Y
        CATIProduct *piProductOnRoot = NULL;: ~0 @3 n3 g: o1 p
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
$ T+ a* S6 |* F5 _                                               (void**) &piProductOnRoot);/ G+ G! w6 D4 _4 Y0 _0 v
        if ( FAILED(rc) ) return 3;
  b) i: t4 E4 r) d
' d7 ^5 f  @$ G1 ]' P1 T        /* ---------------------------------------*/1 X6 O' R, t7 a# _
        /* 3. Retrieves children under the root   */
' m& P1 I3 v4 W4 d! K        /* ---------------------------------------*/
3 O0 I# P( l7 c& ~" x) y% O       
8 N/ M; C+ s: d: o, S        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;
* V! a% v7 S) y7 l. ~) |8 {        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;0 o& g  t; T/ z# b; S  s
        ! Q" W2 ~4 t- S" C( K9 C' ~
        // then on a root product, get all the children agregated to it.$ I" L; M! M1 m4 w# X$ m9 ^& _/ a
        CATListValCATBaseUnknown_var*   ListChildren =
. n1 H1 Z. ~9 J# I% _  O                piProductOnRoot->GetAllChildren();2 D3 B8 P% F7 a
/** @anchor err_2 piProductOnRoot not set to NULL after release */
( b6 j% J6 |/ R        piProductOnRoot -> Release();0 [& r" b+ f) V% r: @0 B5 X
        piProductOnRoot = NULL;
& v3 |4 c3 }6 ^  _( s4 q        if(NULL != ListChildren)
  R, W2 E; P2 Z, D! [4 a' V& ^        {) T8 j' r$ [2 L" L1 O2 @
               
$ ]5 R  |- S) }* u$ s                int numberOfChildren = ListChildren->Size();6 D0 f: E/ |. N: g
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
/ ^) N7 |" D, g1 e. {& M7 u7 `$ q2 n# p) S3 K3 R- g
                /* -----------------------------------------------------------*/5 i* `; s7 n/ u* b2 N' u" q
                /*  4. For each child, get its partNumber, and InstanceName   */
0 b0 j# [. R0 r& {3 R4 {+ Z                /* -----------------------------------------------------------*/
9 \4 u" ~. {, t, c$ T. e7 v9 r0 S                CATIProduct_var spChild = NULL_var;
5 N' L- x' ~6 |6 w% U3 l                for (int i=1;i<=numberOfChildren;i++)- Z  V# l6 Q0 S3 E0 v/ Y' _
                {
  J# a# B" V2 S                        spChild = (*ListChildren);
8 q; R7 x7 d6 v  V/** @anchor err_3 spChild not tested before use ( if !! ) */ 0 {# A$ i/ t9 }
                        if ( NULL_var == spChild ) return 4;
1 v6 m& i3 Q5 c3 z/ r                        CATUnicodeString partNumber = spChild -> GetPartNumber();  {: h0 q+ B6 l; c
                        CATUnicodeString instanceName (" ");7 B3 m- j& H7 b. c2 S* k# M
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;; X. Z7 {9 P0 `$ T
                        if  ( FAILED(rc) ) return 4;( X6 T# y% s  M# s( f0 h
                       
# T# q8 _5 W7 K$ }! \/ v0 W                        cout << " child number : " << i << endl << flush;
5 ^) C) x+ }3 S4 B3 a5 T$ W                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
6 i! c0 K/ b1 C; p  O& V                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;' h: I7 h+ D/ v2 h6 w
                }5 D/ n# p8 E* D. V9 J# k. t
                delete ListChildren;9 Y; ]. ?6 F& _) |
                ListChildren=NULL;; Q0 T; H) `2 k" y) ^) x
        }        . y# R) k5 V& |9 z* @+ V7 f
        /* -------------------------------------------- */8 i3 P0 a8 t8 C
        /*   Ends the session                        */9 ]+ y& E' a) F
        /* -------------------------------------------- */[/mw_shl_code]* B  K. \$ S* ?& f' H. `3 v
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了