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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
  S  e+ `8 b* o$ g$ n
Catia二次开发源码分享: 获取装配所有组件列表) C: B) _7 ?3 W3 q% c) |
& i+ w3 U( P/ e- L9 G3 `2 \+ V

# M+ u$ A+ K+ z  k5 C: ]- ]% H[mw_shl_code=c,true]/* ----------------------------*/
0 m  D; |7 k; \6 Q" f8 W. N        /* 2. Retrieves Root Product   */
5 N" k, \& @+ u- n, T  W+ E        /* ----------------------------*/
2 W( L" `6 W6 S0 J2 ]/ C/ W        ' L- U6 l1 K: `' q& w4 P
        // Begin navigation throUGh the document => start with the RootProduct.
9 _! u) Z( v! C! t; e        CATIDocRoots* piDocRootsOnDoc = NULL;. Y9 F: i2 P" ?3 C# _* _8 n
        rc = pDoc->QueryInterface(IID_CATIDocRoots,  `  R# T, X, V, A! \, E4 l
                                      (void**) &piDocRootsOnDoc);
6 K8 ], @/ O3 `6 S; M9 @+ h" K: G        if ( FAILED(rc) ) return 3;
, _% @: J+ p+ G( i% x# A       
5 S9 _( t* N, j        // get the root product which is the first element of root elements
% o, h" X& \& }        CATListValCATBaseUnknown_var* pRootProducts = 8 s+ o( y( {: m# w
                piDocRootsOnDoc->GiveDocRoots();
1 J& |9 ?) n- o( A$ {, Q  U        CATIProduct_var spRootProduct = NULL_var;: w, G* }5 D. X
        4 r! X' R, b) n* P; i
        if (pRootProducts && pRootProducts->Size())
2 A' K% s& s0 o        {  
# d* n/ S! Q2 S- c8 h( u0 n# U                spRootProduct = (*pRootProducts)[1];/ {, C: I5 M6 l) I0 i  z
                delete pRootProducts;* k$ [4 g/ T* @! G3 ^
                pRootProducts = NULL;
$ ]7 N9 N; W5 R5 x4 J        }4 Z5 e; t6 \- q* ?. G
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ / z) g/ c9 n9 B6 g/ S; T5 U( G$ t
        piDocRootsOnDoc->Release();
7 R' Y% L" n" k/ i5 a        piDocRootsOnDoc = NULL;8 s5 E0 L; G% C# s, c0 d
        " c" u+ C* q: O9 X" {
        // Get CATIProduct handle on the root product.( W, B7 x$ {7 i% |* L& U- T
        CATIProduct *piProductOnRoot = NULL;
% \( v" _8 x6 b; q( l8 Y8 L        rc = spRootProduct->QueryInterface(IID_CATIProduct," G9 w. \- D) M/ `; m* q
                                               (void**) &piProductOnRoot);
- c# A% S3 @- b; k* ]# d        if ( FAILED(rc) ) return 3;( |% c6 b* L/ W7 {7 A' g
; A7 z+ u- v9 s) O
        /* ---------------------------------------*/5 l( C5 U6 c) k# d8 ]
        /* 3. Retrieves children under the root   */6 O0 W, L! o/ d
        /* ---------------------------------------*/
4 e& S* s& T$ m7 K9 U  D6 T       
' n% R% k* O9 L+ i        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;5 ?& \  M9 \# l1 b" @
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
4 j% `5 i, v1 Q: h* a; \! {* g  Z( y        " {/ |/ L" z* w. y" C
        // then on a root product, get all the children agregated to it.
+ w0 c$ J/ `  O        CATListValCATBaseUnknown_var*   ListChildren =
: `* W% o7 ], f8 L- Y8 y                piProductOnRoot->GetAllChildren();( _. r1 `9 @% Q% q6 H
/** @anchor err_2 piProductOnRoot not set to NULL after release */
+ I: w* s/ k$ `$ O! k- m! A        piProductOnRoot -> Release();5 W! o% S+ H1 z0 e% Z# i, n
        piProductOnRoot = NULL;% G  ?5 m+ V" W  w3 I
        if(NULL != ListChildren)
4 V5 [: D9 Y9 x4 f- J2 p/ C        {. N0 b) ^+ ?- t8 `1 H4 K( f9 |
                . w) B" j$ o0 h6 X( H
                int numberOfChildren = ListChildren->Size();) i/ A9 x" J. V) v: K5 S
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;+ Y2 H% @6 ]4 w/ o6 F$ G

, s6 N( b/ M& G  o9 b9 K- L- R                /* -----------------------------------------------------------*/
! n( n# n/ O! b- Y3 E( }2 D8 c                /*  4. For each child, get its partNumber, and InstanceName   */$ n$ k) k* g9 X- T, G
                /* -----------------------------------------------------------*/
3 Z5 c; j7 k: p. \6 s                CATIProduct_var spChild = NULL_var;
6 R) D: f1 }' X9 i                for (int i=1;i<=numberOfChildren;i++): v; k  F7 U3 F1 x8 K
                {5 o9 A4 N0 a( ~% J4 ~1 @5 L
                        spChild = (*ListChildren);7 o" N  C) k' L/ C; T5 h. h
/** @anchor err_3 spChild not tested before use ( if !! ) */ 2 }7 c& f/ X% H3 Q) e9 q) B" m  S
                        if ( NULL_var == spChild ) return 4;
- g' C' Y5 V6 ?. L, m                        CATUnicodeString partNumber = spChild -> GetPartNumber();) F  |8 g- O; [& d+ @0 H5 D
                        CATUnicodeString instanceName (" ");
) N/ ~+ w) z  [' B1 j                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
" _% C, r5 ?+ `                        if  ( FAILED(rc) ) return 4;7 [' M) u9 }- N" J; W
                       
  x9 q0 {9 n) p. g- x* E- w' c/ G                        cout << " child number : " << i << endl << flush;
' S. x: r! _) K. B# Q4 e& M7 y! z                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;: r# Z; H3 P" K: ~& e
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
4 f! D# B+ ^! f                }
; T5 Y& m, F& W0 i3 R5 J- {7 r                delete ListChildren;
' ^2 e' Z; A$ k7 v                ListChildren=NULL;" J: U" Y! e- C* b5 F3 ]1 b
        }       
2 b" |3 ^; @* ]2 u3 K9 n) O        /* -------------------------------------------- */# `1 ?4 D6 |7 }1 k4 u
        /*   Ends the session                        */* b" k' ?) `- o1 M
        /* -------------------------------------------- */[/mw_shl_code]
0 Z5 U& l# T2 M: v0 O& o
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了