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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
$ `5 s) K: g$ _: ~7 q
Catia二次开发源码分享: 获取装配所有组件列表
) T5 X: A1 W; ]. B& k! I$ I0 Z; X. b8 u

% M: I! D' P1 ?2 R% t0 I: C# P) q[mw_shl_code=c,true]/* ----------------------------*/$ c" `# D  d4 L; X! O) z( \1 }
        /* 2. Retrieves Root Product   */
1 p4 A! f2 a6 E9 z3 Z& |# Y        /* ----------------------------*/6 \2 m( M* Q/ }
        9 ~8 O" N& `$ w& S+ _: d6 F
        // Begin navigation throUGh the document => start with the RootProduct.
3 z  Q2 x! }1 u4 U        CATIDocRoots* piDocRootsOnDoc = NULL;
* D+ Z  a4 }* ?, M. n  M$ o        rc = pDoc->QueryInterface(IID_CATIDocRoots,! P& k' u: \9 _: P/ _
                                      (void**) &piDocRootsOnDoc);( @) H& d# \& {# y4 F
        if ( FAILED(rc) ) return 3;
9 I' G: D; m' s; D  b2 g       
0 m; P( S1 `& z/ R* e" x" O  E5 h        // get the root product which is the first element of root elements1 e$ A/ H& U) }1 R1 m2 G
        CATListValCATBaseUnknown_var* pRootProducts =
  D( X! G. Q) v/ U, G3 P                piDocRootsOnDoc->GiveDocRoots();) b, B1 @. d; C2 H9 w5 `/ d( Z( D3 a
        CATIProduct_var spRootProduct = NULL_var;4 e1 b  }! V% b2 z
        8 w" _" @( s8 x" ^
        if (pRootProducts && pRootProducts->Size())
, R" @  ~* ]" x4 C5 h* U        {  
* H4 S, u/ K) @# A$ V; _( P- E                spRootProduct = (*pRootProducts)[1];- }( r+ c6 o! O( G2 x. R+ q5 |
                delete pRootProducts;9 n# X' a7 R( _0 k  g
                pRootProducts = NULL;
& R5 e+ ^! A: p/ w        }
- v% s9 I, N  F) E/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
* O' F0 Q% q# n' v6 A4 P" u' C        piDocRootsOnDoc->Release();
, L$ H8 f0 F9 G% k2 d+ N% k        piDocRootsOnDoc = NULL;; L. U- d" a+ o) Z  ?
       
( n' D/ P; y6 Q0 U        // Get CATIProduct handle on the root product.
+ J0 M0 h9 c. T( X        CATIProduct *piProductOnRoot = NULL;) N/ c( h/ {" t' n9 f) z
        rc = spRootProduct->QueryInterface(IID_CATIProduct,9 ^1 ~1 J& y* S, U0 h' e! m
                                               (void**) &piProductOnRoot);5 k: [9 r$ b. ~" v) {
        if ( FAILED(rc) ) return 3;2 z0 U. v- O4 N; a; D2 X( ]
' L- h, D8 v1 m1 x5 n
        /* ---------------------------------------*/, V1 A) g) n% u5 K2 h9 Q7 y
        /* 3. Retrieves children under the root   */% y: M0 o5 H- F2 N5 l: B1 W
        /* ---------------------------------------*/
1 ?3 H$ h8 ?; E        0 C5 }2 e: T3 y7 g8 Z
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;' H/ ]6 L; P4 t
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;& c& L( @8 @: o" U4 k
        + c+ o8 S3 }) T6 w1 l
        // then on a root product, get all the children agregated to it.
0 `! M5 C& R1 q9 ^! R        CATListValCATBaseUnknown_var*   ListChildren =- W- ~( D& c+ G
                piProductOnRoot->GetAllChildren();  r1 b& m! \2 T
/** @anchor err_2 piProductOnRoot not set to NULL after release */
) C3 J* D" H( c3 Y& t4 R        piProductOnRoot -> Release();
& ^9 v0 g& B" Y0 I# k        piProductOnRoot = NULL;
3 f7 }) A) d$ F  w- i6 c        if(NULL != ListChildren)
  \7 N7 u, T/ Y2 w0 `7 j9 K! v! r        {
. F) {% h8 u- O; ]" o$ D                # t. F5 r) _8 Y
                int numberOfChildren = ListChildren->Size();4 G; r$ W! t2 _' i
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;$ X5 D% E5 y$ a1 x: S

# H  _# ]3 S, r& S6 x! _: Z                /* -----------------------------------------------------------*/4 m4 u& A7 {% e; i1 X. b0 R
                /*  4. For each child, get its partNumber, and InstanceName   */5 |  _! r2 M! j: Y7 J
                /* -----------------------------------------------------------*/
/ C- i6 ?3 V/ o$ c                CATIProduct_var spChild = NULL_var;. G3 r* j: D% R6 a  G0 T% Z
                for (int i=1;i<=numberOfChildren;i++): G( t. c) L8 f+ R
                {
/ ^' Z+ n' P4 a, N- H1 d: e+ f* `                        spChild = (*ListChildren);
2 r2 i% a! R0 a) t& s; O/** @anchor err_3 spChild not tested before use ( if !! ) */
# S) t' w$ c* c1 D                        if ( NULL_var == spChild ) return 4;
9 }' H7 e' P7 ^5 A3 R                        CATUnicodeString partNumber = spChild -> GetPartNumber();
: c8 V+ M& l7 g                        CATUnicodeString instanceName (" ");
/ s/ o. |5 m6 u, a                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
. L/ O5 a& a# J1 ?$ [* I                        if  ( FAILED(rc) ) return 4;
: i( O4 T/ T' e! e6 {# u: t                       
: C% `5 B  ^# q  N" y4 F. C1 g                        cout << " child number : " << i << endl << flush;
" U9 I% `5 E  s/ f; t/ o0 j% ^  E                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
7 P, G- }( j9 x- E) s7 o                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;) m+ N6 i" E( _6 K! D$ N9 [0 r
                }3 B% H" g, ?8 w  }
                delete ListChildren;
- S) [/ h+ [7 i% Y- W* |                ListChildren=NULL;' ^1 L; N: d  J4 H
        }       
# m% d' L  D$ }$ M3 T+ j$ r$ X        /* -------------------------------------------- */5 D" U: q5 A# a) i/ ]
        /*   Ends the session                        */
, ~- N2 S5 ]. F1 k$ r+ \6 t" P        /* -------------------------------------------- */[/mw_shl_code]
' S& Z* P! l6 J# M3 F
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了