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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
  S5 b$ h& _! O' L. D
Catia二次开发源码分享: 获取装配所有组件列表
1 k) s: y5 q4 j, j4 p" \: R
3 Q! v+ c- q" {  ~# v. d
5 I$ l& f: W6 l9 o5 D[mw_shl_code=c,true]/* ----------------------------*/. K. ~3 k% F# i6 O
        /* 2. Retrieves Root Product   */) i& U# Z/ `( O0 ]1 K- Y, e
        /* ----------------------------*/+ M  F, Q/ T" K* }9 \: W5 O% i3 J
       
4 |, F- m; t. C6 n6 x& \5 q        // Begin navigation throUGh the document => start with the RootProduct.+ a" a: U- F6 e8 J. M( Q3 E( [
        CATIDocRoots* piDocRootsOnDoc = NULL;
' d  ?/ X! g. b        rc = pDoc->QueryInterface(IID_CATIDocRoots,  _- I: w' B: Q1 U, q& X
                                      (void**) &piDocRootsOnDoc);
% v( R4 V- ^1 R; }2 V, v" w        if ( FAILED(rc) ) return 3;1 y' e; {$ @4 w
       
1 q' `2 h) Q7 ~: v, C        // get the root product which is the first element of root elements
( p& F2 K8 I" z        CATListValCATBaseUnknown_var* pRootProducts = ; }$ X, X% z& ^7 U6 O! X
                piDocRootsOnDoc->GiveDocRoots();
) _- q! G2 s* H        CATIProduct_var spRootProduct = NULL_var;
) M0 h% |3 j/ Y4 b8 {" t( {        9 v6 b$ O6 T6 K) Y: P  T; y. Y
        if (pRootProducts && pRootProducts->Size())
6 L) w9 P) U, I, L" B        {  
' j& w: G0 e6 d. N5 G                spRootProduct = (*pRootProducts)[1];2 y5 j* r5 Q0 R2 x) U3 c
                delete pRootProducts;
7 ?  i& P" L8 ~4 o9 C8 Q                pRootProducts = NULL;& j0 [  n; n7 R4 }7 m# ?" [
        }- C% v: a3 ?6 {, f; a
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
* d) I) q1 B/ x7 l) T9 U5 e" ~  J        piDocRootsOnDoc->Release();/ B) ^9 B1 A7 s' G, Q
        piDocRootsOnDoc = NULL;6 i" E# F# B# g- Q" S! N8 s3 a
          P; {2 _: o3 d: C/ S: c
        // Get CATIProduct handle on the root product.
5 D# Y/ |! }! Z4 H2 q; h        CATIProduct *piProductOnRoot = NULL;2 }* B" Z5 r, Y5 ~" `1 D
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
: V- y# h' L) U+ X& I" ]% W9 a9 i                                               (void**) &piProductOnRoot);
' ?  F; B2 _' x+ ?- y, F+ f. M        if ( FAILED(rc) ) return 3;/ |/ ?0 A1 _* X: ]& K2 C! o

5 G- p1 P# C- f" y2 y7 W, ~        /* ---------------------------------------*/# Y# L, @  C, l# u
        /* 3. Retrieves children under the root   */
6 h5 M- [/ m4 S2 J/ c2 \7 y7 b. _/ R        /* ---------------------------------------*/
8 N3 d* l: }7 `' L+ C( @4 F- p        5 H8 g  I# z+ I* m
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;
/ J$ y' L3 T$ R6 f/ O        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
. a, V$ K- S: K        + E! F* o. R9 J; @5 w/ R4 I+ p
        // then on a root product, get all the children agregated to it.; x, T+ J  r+ M- K9 r
        CATListValCATBaseUnknown_var*   ListChildren =: N: |) K' Q8 ~5 P' n5 r% N( Y8 j
                piProductOnRoot->GetAllChildren();
% u! \& g6 A3 a4 l6 P$ b9 `: k/** @anchor err_2 piProductOnRoot not set to NULL after release */
3 J4 g& [" _2 R+ R  {) ~        piProductOnRoot -> Release();
, r, y1 J1 ?7 z5 N# j. W        piProductOnRoot = NULL;
& q; f' @! C& Z, L2 w9 v. \4 i        if(NULL != ListChildren)3 a; ~2 l" u0 u- j3 o+ \+ x0 `
        {8 B1 w; _6 d. Y. _
               
: ~9 T& {% W  ?. x; Y. d                int numberOfChildren = ListChildren->Size();
$ N3 Y: W; A2 ]+ A7 v* b1 ?0 v7 Y, c                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;5 d4 S, N% r% j) B4 G! [
$ c3 G4 W3 p- D& G0 @9 o
                /* -----------------------------------------------------------*/4 l+ Q, }0 w8 {/ t
                /*  4. For each child, get its partNumber, and InstanceName   */! |& d3 I5 |! `9 z4 \2 x
                /* -----------------------------------------------------------*/; [) `, M- j9 `+ Q1 [) m9 R
                CATIProduct_var spChild = NULL_var;$ B. C1 ?( Z4 R  G; w
                for (int i=1;i<=numberOfChildren;i++)6 U( X1 a5 ?) t! V$ k  N1 a: ^
                {$ \4 }$ b* Z! g2 ]1 p
                        spChild = (*ListChildren);7 X  m) _( S/ [; O: y5 L0 M
/** @anchor err_3 spChild not tested before use ( if !! ) */
- B$ H0 w/ n% X                        if ( NULL_var == spChild ) return 4;
: X7 J4 o5 d, n% `# x7 b# ?                        CATUnicodeString partNumber = spChild -> GetPartNumber();9 _5 u( K# w; f7 n1 q$ s1 T5 A
                        CATUnicodeString instanceName (" ");& u" X: q) F. l; E1 _' U3 v
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;. p* p  f/ k: z" K( i9 \$ i
                        if  ( FAILED(rc) ) return 4;
. n* d- M" L' E5 l# C                       
. Z6 e+ c# U6 }9 J6 W% y1 }                        cout << " child number : " << i << endl << flush;! F0 f2 U( }7 M
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;' w+ v- z* M7 J9 j0 d
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
1 V9 t; e& L1 V% y                }$ a" W0 K) c# G5 _6 z. I+ A
                delete ListChildren;
7 H+ N! f. f8 d$ |7 P6 Y$ ^- x8 ?, D                ListChildren=NULL;
& ^3 a$ {* M! R+ H/ e        }       
& _7 Z8 W1 g% ]7 ^5 h. o( g        /* -------------------------------------------- */
0 b! t& k" \4 O0 t# U3 X2 K        /*   Ends the session                        */  n$ N( R; i) \4 k7 N! t( m
        /* -------------------------------------------- */[/mw_shl_code]
# c6 n% a9 i7 `3 A8 o7 r
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了