PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82166
QQ
发表于 2018-1-10 10:12:25 | 显示全部楼层 |阅读模式

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

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

x

0 v- E: y! A9 h4 b4 V, x& ICatia二次开发源码分享: 获取装配所有组件列表
: _# _# Y1 y+ |& N
' e5 h1 O6 y8 X" Z' e2 B3 ?& n
[mw_shl_code=c,true]/* ----------------------------*/7 H( [' t! C. ^6 ]( S, M
        /* 2. Retrieves Root Product   */6 d  E' W3 ]. z2 |/ L% _) B
        /* ----------------------------*/) e# k, e" s1 ]! J
       
; w0 l3 q# x0 t& o, L        // Begin navigation throUGh the document => start with the RootProduct.
5 R4 ^' X. X9 ?0 r/ c& `        CATIDocRoots* piDocRootsOnDoc = NULL;
2 }6 C0 f; k/ k: E; w: G" }        rc = pDoc->QueryInterface(IID_CATIDocRoots,
- |0 ]# ?" g. J( r; l% Z3 O                                      (void**) &piDocRootsOnDoc);# k! x' s. o% K+ x% ^4 O7 x# l( x
        if ( FAILED(rc) ) return 3;
* V! e' q6 P! p6 S$ k        1 F" p* }# K  d; G$ R
        // get the root product which is the first element of root elements7 g9 T2 Y* A% |9 I/ v. U; I9 _
        CATListValCATBaseUnknown_var* pRootProducts = & |! p$ H6 R; s( T
                piDocRootsOnDoc->GiveDocRoots();* R. U, [* q7 l; d
        CATIProduct_var spRootProduct = NULL_var;
, A' S. q2 _3 L/ J% i" F       
. O  g) u5 R2 p* M9 v* k! U        if (pRootProducts && pRootProducts->Size())- g9 _; `' e9 L  `# l4 T6 t
        {    [' d3 N) z9 w, V1 n5 j
                spRootProduct = (*pRootProducts)[1];, Q) z0 c& f0 e  I, H  O" _' p+ p
                delete pRootProducts;
! Y0 L3 E) U6 I6 V% C4 M+ z                pRootProducts = NULL;* Q- Q. A- o1 m  F) S: t: O' z
        }
1 V" D1 W; g/ l4 `9 f) \/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ ' t0 C4 D6 C8 F5 Q
        piDocRootsOnDoc->Release();1 \. Y% S, p) Z7 ~. @$ f
        piDocRootsOnDoc = NULL;
" g0 I' t. B# u# [       
  I' P1 k( E. E+ c  J! }        // Get CATIProduct handle on the root product.
& X1 @# Q0 ]" E; [! u6 f+ X/ [        CATIProduct *piProductOnRoot = NULL;
9 a4 O; F% @" V! ]        rc = spRootProduct->QueryInterface(IID_CATIProduct,
6 ]( ~# Y8 s- |) y- ^0 z                                               (void**) &piProductOnRoot);
1 s4 p( _; [* t! R$ k" O        if ( FAILED(rc) ) return 3;  e% X9 x  B: y: K, Y

# I! T2 \' S* p4 |        /* ---------------------------------------*/
) G6 L" Q7 D4 W+ @        /* 3. Retrieves children under the root   */8 C4 w6 i7 f. e. ^$ w- W; p
        /* ---------------------------------------*/7 C! o1 x! F: Y( i6 G
       
1 c  A8 B* h$ n/ R' X4 d& s        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;) i0 c, U7 K5 u; y* \  T
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;! b6 Y0 w5 g9 R0 Q. t9 V3 k' A
        3 d' l+ U8 B* _4 G) g" @
        // then on a root product, get all the children agregated to it.& M" Q8 M) N1 U& C5 ?8 a& V
        CATListValCATBaseUnknown_var*   ListChildren =4 N# g' |) X2 T- c9 B( E. O
                piProductOnRoot->GetAllChildren();
! \% S9 D3 G8 \+ R: g6 J. ?& ^5 ?) z/** @anchor err_2 piProductOnRoot not set to NULL after release */ ! b: c6 b: L3 u2 a4 y
        piProductOnRoot -> Release();  H. e1 @5 i# Z! ~9 h" u
        piProductOnRoot = NULL;, _% {5 _9 P1 U) ~, Z/ d
        if(NULL != ListChildren)8 v9 b- d7 h% r" S3 k- s) I
        {
  E2 e9 F: q0 m7 {               
% x" z& @4 b% p) f: e                int numberOfChildren = ListChildren->Size();
+ `0 |0 H" z3 ~( P5 Y* e: O                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
3 @: h( j6 h3 e5 D5 A# X% c7 Q  E0 J, c: ^
                /* -----------------------------------------------------------*/
  o6 F6 _% O! @: \: |6 o8 {                /*  4. For each child, get its partNumber, and InstanceName   */
/ @, |+ V* f: Q: i! h7 D! K                /* -----------------------------------------------------------*/
) R* J9 i+ x! ~' r                CATIProduct_var spChild = NULL_var;
4 `& s9 i8 h) @- D: L                for (int i=1;i<=numberOfChildren;i++)4 V9 _$ n( X5 _  g
                {! ~/ Z& a9 _( ]4 L
                        spChild = (*ListChildren);
7 K1 `8 l  j) x1 v, _" s/** @anchor err_3 spChild not tested before use ( if !! ) */
2 P/ A; w3 k& J+ e/ i                        if ( NULL_var == spChild ) return 4;1 h& e: |  S: w% j4 ~; d) m$ \
                        CATUnicodeString partNumber = spChild -> GetPartNumber();
, {2 T6 {+ {3 f" f; Z4 x6 O                        CATUnicodeString instanceName (" ");0 `3 e  e8 W" t8 c. {
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;) Y4 B9 I( n" c. K9 L( J
                        if  ( FAILED(rc) ) return 4;
! M9 M6 z' r" L# ~2 N                        * O5 Z" A+ q% O* J
                        cout << " child number : " << i << endl << flush;+ o4 l% M! s. g3 y: J  _0 Y2 f2 H
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;' c! N) B6 |: Y$ ^
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;+ x  F  c' L; w
                }
0 f4 W$ t* S) @                delete ListChildren;. V# |+ L1 c5 b2 O* A; I: R
                ListChildren=NULL;& U/ l7 ^" S/ L+ a5 M& U
        }       
/ s; n  C( V* m7 z; A        /* -------------------------------------------- */! }! p! Q: L& I; i
        /*   Ends the session                        */
- r1 O; e* S( z) |/ V. q' P        /* -------------------------------------------- */[/mw_shl_code]4 c9 U7 K. [* {5 q7 }
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了