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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

9 `. [9 ~( v0 b, f( i" e; o" P5 OCatia二次开发源码分享: 获取装配所有组件列表* e3 @6 k$ M. p  K
! ?5 O3 V4 J3 K! ]
' L( M1 J. H% [3 K! T
[mw_shl_code=c,true]/* ----------------------------*/
7 }; u9 E& b6 [+ s        /* 2. Retrieves Root Product   */
8 C% }' h* ]% _. [        /* ----------------------------*/' Z7 k& }8 L* Z* S* d
        9 {1 U" M0 J2 d. H( ?# s
        // Begin navigation throUGh the document => start with the RootProduct.  M5 m% O1 c0 f3 y0 D
        CATIDocRoots* piDocRootsOnDoc = NULL;+ L' P5 f3 z; @, A- [
        rc = pDoc->QueryInterface(IID_CATIDocRoots,; P' c  _# S9 S3 r
                                      (void**) &piDocRootsOnDoc);
5 K  K$ c  }( X9 |4 x' T3 A1 J; `        if ( FAILED(rc) ) return 3;
- ]( D0 A/ T' n# e       
* h3 T8 ]' j% E4 F        // get the root product which is the first element of root elements
" F% N0 D$ w8 j, E. p        CATListValCATBaseUnknown_var* pRootProducts = & A; N$ l% G6 @( R% e" n9 l' U5 y
                piDocRootsOnDoc->GiveDocRoots();
' q3 o; }( M5 ]0 _, G        CATIProduct_var spRootProduct = NULL_var;% ~/ r5 ~% a& ~6 m: d8 ?: a6 D
       
( c3 B3 U9 b  w& f        if (pRootProducts && pRootProducts->Size())
, j( b  `- m3 v% c( q' l7 Z) F        {  0 Y) M# D/ ^2 S. s) I* q
                spRootProduct = (*pRootProducts)[1];
& V  f% x6 L" E6 m% Q8 T3 G5 ]                delete pRootProducts;
5 f7 D- y4 k9 y$ C" I                pRootProducts = NULL;
$ t5 \8 T6 C1 N  t; @; \7 l) S        }$ ?0 e5 @  G( a1 |4 T* V
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ 9 `  M$ Z3 B+ c- H
        piDocRootsOnDoc->Release();
% Y9 Y$ g! U5 ]8 O$ t9 C        piDocRootsOnDoc = NULL;8 @5 b2 N5 p1 H+ n
        $ d8 ?$ Y" c) X" b7 \
        // Get CATIProduct handle on the root product.
  z% U5 z* l& r1 _- `# h        CATIProduct *piProductOnRoot = NULL;3 ^" R/ `' {  ^( R' C9 A6 ~
        rc = spRootProduct->QueryInterface(IID_CATIProduct,& Q$ z$ \. A" I' `; {" h" `
                                               (void**) &piProductOnRoot);2 I% B: _  R  V# r- K
        if ( FAILED(rc) ) return 3;5 S7 y% Y) |  y! G1 ^7 I5 K$ _

9 X/ X1 L) |8 z/ E9 M) `        /* ---------------------------------------*/0 z/ ?! K4 P; x- T+ p' j
        /* 3. Retrieves children under the root   */, V& \8 u) y+ P9 k
        /* ---------------------------------------*/) ~% ^5 W: {3 s' Z% f5 v& h. I
       
3 P3 S+ ]; ^( J; A4 o8 S4 B3 f2 N        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;6 i4 u: d4 I& U7 a9 `& T3 ^9 d  A
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
3 ~# r1 s9 v) X' n3 {        / F8 h; I: ~3 b. L
        // then on a root product, get all the children agregated to it.# X; K, }: o9 }% d# {. x( p
        CATListValCATBaseUnknown_var*   ListChildren =
# R' l7 Z8 g* s2 r& `- b                piProductOnRoot->GetAllChildren();
5 z: G8 m0 u; ?: z2 _4 q& g6 ?/** @anchor err_2 piProductOnRoot not set to NULL after release */ 4 p, u3 y9 \' I# `4 U
        piProductOnRoot -> Release();
- t9 P4 t! g5 f5 S) t        piProductOnRoot = NULL;8 @' _& I$ d8 B0 w# X+ }' Z
        if(NULL != ListChildren)+ n' |2 X0 X! {6 a) D
        {% s. t* c% c' D# \) A! i
                5 L2 F! Y' @' B: D3 O' U
                int numberOfChildren = ListChildren->Size();& R) L) w+ `! i$ B6 ~' Z
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;9 D" F: a2 L. B! B' w

4 ]$ @' g" }  C2 w1 V                /* -----------------------------------------------------------*/
% [' {. {+ |2 j$ d                /*  4. For each child, get its partNumber, and InstanceName   */
7 P  T" E) k: s) r                /* -----------------------------------------------------------*/
$ L% \  q: |8 Y. j+ t) H3 O                CATIProduct_var spChild = NULL_var;) d* a7 u: [- S6 C  h" a, V6 D
                for (int i=1;i<=numberOfChildren;i++)
7 [' F3 A( ?3 \$ H6 [                {9 J5 z9 z( P" a6 J" N# K9 x8 z
                        spChild = (*ListChildren);
8 F) L7 d( |" l! B/** @anchor err_3 spChild not tested before use ( if !! ) */ " f( s4 h- Y) Q; C1 M
                        if ( NULL_var == spChild ) return 4;' Y& X. ^: S* Z. F  G- o* |4 p
                        CATUnicodeString partNumber = spChild -> GetPartNumber();
2 E1 ^& [9 m: |/ g5 z; D                        CATUnicodeString instanceName (" ");4 ]. y, f6 I$ l8 A' U; K
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;" S! n+ Z6 B7 {6 }  w& ?- C, B
                        if  ( FAILED(rc) ) return 4;7 {2 x* `* T5 g1 _, D
                       
! w' S6 X1 @7 j# a  _                        cout << " child number : " << i << endl << flush;
, m. u. D# ~; Z/ N0 t+ u6 q                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
, q# A& M1 |7 d9 j7 y' M, Q+ P                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;3 [! t- u$ X4 c  D9 |
                }
6 j% D& ~6 }' A3 A* k3 ~7 N. V                delete ListChildren;# c  S' |$ b" y
                ListChildren=NULL;
' n& w+ V9 E; h- ^$ y8 I        }       
! P% t3 e0 ^7 b, F4 e6 f) }6 ]        /* -------------------------------------------- */
  k  W+ b7 I0 h# w# K        /*   Ends the session                        */
+ W: l3 B3 E: Q. M8 Q$ R$ w        /* -------------------------------------------- */[/mw_shl_code]
& W. V4 f- A* J4 \9 O- y4 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二次开发专题模块培训报名开始啦

    我知道了