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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

9 a- G/ p, _* QCatia二次开发源码分享: 获取装配所有组件列表
" N7 \3 I& C% F& Z
  v% h. G+ c6 R+ ]3 Y1 j* A8 {
& E1 L2 M: ?" \( t[mw_shl_code=c,true]/* ----------------------------*/
4 u8 l( x# N9 o& @/ ]8 V        /* 2. Retrieves Root Product   */
6 S0 C# O0 z, Q% y' h        /* ----------------------------*/
" y( b* f" p/ Y. o" e: c' M0 A       
, Y, I4 [  A; u        // Begin navigation throUGh the document => start with the RootProduct.
: F& U% q9 }, N" W' ?        CATIDocRoots* piDocRootsOnDoc = NULL;7 u5 o. c# z3 b( Q+ t
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
3 W2 D0 q" K3 R                                      (void**) &piDocRootsOnDoc);
# r4 j6 m. b3 K* o, D        if ( FAILED(rc) ) return 3;' N/ o4 {: a$ E6 B" n" u2 z+ Z
       
( Y3 @# k) d+ Z9 V4 A' v6 q. E- c        // get the root product which is the first element of root elements' G3 Q2 U+ Z; V+ G" _
        CATListValCATBaseUnknown_var* pRootProducts =
, k% y( w: s; E% v% Y, E                piDocRootsOnDoc->GiveDocRoots();
- I) T0 l# }6 f# G        CATIProduct_var spRootProduct = NULL_var;
& W& _, y$ b! ?6 W7 ^        1 j% l1 I) x: y- v! g( h8 O
        if (pRootProducts && pRootProducts->Size())
  O' `/ T. A  q( j, m! w        {  & U8 j- p' [+ J* F+ G% z- N. H
                spRootProduct = (*pRootProducts)[1];
7 O9 {* j% c  W. |. r1 ?' \                delete pRootProducts;
7 S7 R" e2 s9 j7 W; [8 a  v9 o! a7 D7 }                pRootProducts = NULL;
9 X  b" J, {  ]& ~. T  l8 c        }% h5 z2 b# g! c" u0 y" V
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ % K& c. B( F! j( a/ I
        piDocRootsOnDoc->Release();8 Y2 ]0 ?) [7 c# k
        piDocRootsOnDoc = NULL;5 d: h6 I4 Q$ s$ v' g
       
- V3 ^! t3 O( s0 ?. i        // Get CATIProduct handle on the root product.
- q6 t+ g6 H* ~9 b* \        CATIProduct *piProductOnRoot = NULL;
  ?, f( R' r( K1 U9 {: W( b        rc = spRootProduct->QueryInterface(IID_CATIProduct,. E" _1 f0 m4 w5 A
                                               (void**) &piProductOnRoot);" U7 `. [! G# f! f8 \2 r( e& R
        if ( FAILED(rc) ) return 3;2 I" O$ `8 C  s" b- Q

' ?0 U* z( G9 [        /* ---------------------------------------*/
; ~( }! {4 G# A! R! a0 R        /* 3. Retrieves children under the root   */( g8 o2 n* u) @3 `
        /* ---------------------------------------*/
3 m# D6 {2 u9 u4 N( D( Q       
! F/ n' P% U0 ?. Z' d2 I. v5 f! h9 G& c9 b        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;
3 }7 U' n. ]  A        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
/ E* Q* t$ G: G" G3 j        1 {1 h7 k( m2 c6 p3 [
        // then on a root product, get all the children agregated to it.9 F; D& S" x1 Z+ e  f2 ~
        CATListValCATBaseUnknown_var*   ListChildren =  p. ^/ {9 i. L1 _' D* u
                piProductOnRoot->GetAllChildren();. Z/ i- O! c# N5 P% |  v
/** @anchor err_2 piProductOnRoot not set to NULL after release */ ! i8 |- r) f0 }6 B2 a/ n6 }+ _9 B
        piProductOnRoot -> Release();
0 a- e7 R+ B; p' l0 u  q) f8 K        piProductOnRoot = NULL;) a! K( w# k$ @/ @/ E
        if(NULL != ListChildren)3 x+ f' N% U/ U* G1 K
        {; J$ R5 ]8 o' E' r1 m5 B
                7 o, K" ?& h1 j! Q% x( I% H
                int numberOfChildren = ListChildren->Size();
6 [( X1 ^" g6 g6 c4 O                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
, |8 ]7 }7 l7 H% s0 W/ ]3 l  k* {* S& U
                /* -----------------------------------------------------------*/0 c) \: F2 G8 q* _
                /*  4. For each child, get its partNumber, and InstanceName   */6 @) q0 r( e, o0 z
                /* -----------------------------------------------------------*/4 L' Z% V" W! ?
                CATIProduct_var spChild = NULL_var;) ?8 V# C: [# X: t+ @+ o2 Y; [
                for (int i=1;i<=numberOfChildren;i++)- k1 }) S" N4 [
                {7 r) \. E% [5 w0 ~" U( u
                        spChild = (*ListChildren);
; d* v3 ]" P9 x& S7 G/** @anchor err_3 spChild not tested before use ( if !! ) */ 2 V( [2 _* u+ |  v1 O1 g4 E- l; j4 @
                        if ( NULL_var == spChild ) return 4;
/ f+ G8 O: u% t# K                        CATUnicodeString partNumber = spChild -> GetPartNumber();9 k4 [$ |/ s7 z! U! @0 z
                        CATUnicodeString instanceName (" ");- v6 r/ ?4 Z: ?& b
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
& y. x- c+ s* Z* q3 y6 ~7 k2 m                        if  ( FAILED(rc) ) return 4;! S+ ?& [2 z& ^% |, G7 c$ j4 g8 \
                        7 A2 E7 I/ Z. |# h( [7 @
                        cout << " child number : " << i << endl << flush;8 C/ K" j/ n- h- S/ i9 q( D
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;& T3 J& M( @4 S" z6 r
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
/ ]0 W/ K8 y& j' ]4 T- r9 b                }. r; o/ m& S  I
                delete ListChildren;* m# Q& k, v$ o
                ListChildren=NULL;
, W: G9 e1 L! z! d' D8 [1 e. \        }        # Y& f4 O" I& T$ \6 t# ]5 p- D4 P/ n
        /* -------------------------------------------- */
6 s  W2 B! R7 r' c        /*   Ends the session                        */
# b( [; J# Z: e% ?  P) v" j2 @+ E- V        /* -------------------------------------------- */[/mw_shl_code]
8 D: ]3 z% w$ F- e1 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二次开发专题模块培训报名开始啦

    我知道了