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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
5 H4 X$ o4 b6 E! X( [
Catia二次开发源码分享: 获取装配所有组件列表
* U; @0 J* Y7 [! c% g1 d" U
  {% ^& i6 L- f  K6 k* M0 R7 m+ I4 x4 u) G' D9 K1 c
[mw_shl_code=c,true]/* ----------------------------*/& v* X0 _- @, r1 U
        /* 2. Retrieves Root Product   */( \0 i; f# a1 e8 h4 e: F2 A  e7 p
        /* ----------------------------*/* e+ X+ J5 I0 o) j9 E
       
8 Y' c( T, ]" A0 x4 y, o0 n        // Begin navigation throUGh the document => start with the RootProduct.
/ @4 N- o3 t/ h$ A0 s% d6 X( B        CATIDocRoots* piDocRootsOnDoc = NULL;1 W: T8 g9 P. v2 g1 a, @$ X- d
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
5 Y, I- E7 x7 P* D, l8 _8 p8 n                                      (void**) &piDocRootsOnDoc);
$ Y' ]- r1 K6 }! R, h6 }        if ( FAILED(rc) ) return 3;) x7 l8 `6 M3 s( n( ?
       
9 x& n" l3 Q) m/ B0 Q. ?        // get the root product which is the first element of root elements# k7 y: \( [6 S' V8 i- o3 N1 m) ]
        CATListValCATBaseUnknown_var* pRootProducts = # |' v7 N& ]& g0 W
                piDocRootsOnDoc->GiveDocRoots();; R# a( g' q1 m8 z' b. t$ X
        CATIProduct_var spRootProduct = NULL_var;
' m! K' w; h+ `/ A        + c! w+ D- W+ Y# p/ g
        if (pRootProducts && pRootProducts->Size())
1 W3 F# x& `& j        {  
* T& x/ V6 M  |6 ]# s                spRootProduct = (*pRootProducts)[1];
4 ~1 J% N: r3 J" `# l: s                delete pRootProducts;$ [# K0 Z/ b  `$ ^4 z" W* L
                pRootProducts = NULL;. M; M# [5 s# Z, _
        }
. m. E: B+ O5 R% X& ?; d/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
3 |6 a. D3 U4 X        piDocRootsOnDoc->Release();7 Z$ ~0 [" f& b& h$ `- `+ x. d
        piDocRootsOnDoc = NULL;
0 X% t; m4 y9 l# w        9 M* k% C7 w; b; q- h3 G7 }
        // Get CATIProduct handle on the root product.
; [& r0 |+ f+ S, E        CATIProduct *piProductOnRoot = NULL;5 V, b' }9 h' H; p
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
5 _0 g  p/ C3 O# t$ x( a                                               (void**) &piProductOnRoot);
7 w+ p3 s4 r  o! b) e* I' b        if ( FAILED(rc) ) return 3;  F1 {8 S- q5 i  X+ Y
/ h6 R7 Y) Y( A0 K0 J
        /* ---------------------------------------*/& Z  G& b9 e; u, I- b( T
        /* 3. Retrieves children under the root   */& n1 z; E) ]5 i4 L  w
        /* ---------------------------------------*/
2 C" R* b1 G) n5 s       
3 k* r+ O/ y8 ~* f6 ?2 ]8 z* A6 c. \        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;, k: h$ k5 j* ?  }
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
1 n5 _! |4 v7 G9 [. w4 c3 x       
/ n% R6 E4 M6 i3 E: A- v5 O        // then on a root product, get all the children agregated to it.
/ C! h5 F% o+ v$ H0 v* H' h5 p9 Q: ~        CATListValCATBaseUnknown_var*   ListChildren =
* L9 L& ^1 l2 d4 y6 f  _, `                piProductOnRoot->GetAllChildren();
( N- q8 ?% w0 }+ l/** @anchor err_2 piProductOnRoot not set to NULL after release */ 0 ^9 B& q, v" |1 Q" b& X
        piProductOnRoot -> Release();
) l, N+ S7 ~# O* j" A. Z$ ~        piProductOnRoot = NULL;
9 e+ R/ w$ v! B* F" u& X: \        if(NULL != ListChildren)6 |! v( T9 v/ ]( D8 t8 x+ }9 g
        {
2 C9 T5 p- E: [- `! ]3 r# @7 p                5 ^$ ~( R% o5 _  j6 l' R
                int numberOfChildren = ListChildren->Size();; C, [3 x7 Y3 f; M3 F# l" i. J
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
4 Z2 c6 P4 m5 S. Z% a  D
5 p0 \3 M: b  e+ }8 g  s                /* -----------------------------------------------------------*/0 \& t$ Z2 ~% J5 ~9 v3 m# M
                /*  4. For each child, get its partNumber, and InstanceName   */
* B! M7 N8 ~* ?                /* -----------------------------------------------------------*/3 s7 l  W: P6 {9 I, c
                CATIProduct_var spChild = NULL_var;  Y% B' \& k" _
                for (int i=1;i<=numberOfChildren;i++)8 D% [; m- n+ Q1 _! _( }
                {
+ t( G8 W; h, k5 Y                        spChild = (*ListChildren);
  w. L2 s9 L# O; g3 e6 }/** @anchor err_3 spChild not tested before use ( if !! ) */ ; A0 b& C" q- W, T4 K. @
                        if ( NULL_var == spChild ) return 4;
$ I* j* o3 g& h$ i) v: y                        CATUnicodeString partNumber = spChild -> GetPartNumber();
! i8 |. a. h9 g$ M' d( R* h: d  N                        CATUnicodeString instanceName (" ");9 w  X3 J% V3 F( h
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;" K. B- l; W4 N$ ]5 X
                        if  ( FAILED(rc) ) return 4;/ E% h- K. P4 d6 [
                        / W) H$ f* y+ X9 j5 _$ Q1 u8 J
                        cout << " child number : " << i << endl << flush;
& ^4 N7 X! u/ k" M# c) i                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;3 l& L/ Z. [! O' `5 f, |* `
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;0 G) n- D+ s8 a# b* {# [; i
                }# D# X$ {+ L. `* H' p5 C9 _
                delete ListChildren;$ h3 W: V1 w3 Z6 J9 F* F
                ListChildren=NULL;1 I) l2 d) ~+ S: [
        }       
; `/ A! q: ]* ^+ s4 _& T- O9 M# Q# C        /* -------------------------------------------- */) ]: \% e' v2 l* v) _0 V9 J
        /*   Ends the session                        */1 z" D% ]1 c- ^; }& C+ w: i
        /* -------------------------------------------- */[/mw_shl_code]
8 d1 ]! \0 S; m0 D% g- k! b
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了