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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
  P7 S3 I7 e1 Z! ]1 w. H
Catia二次开发源码分享: 获取装配所有组件列表
# B% }- O% W$ L/ L& k
  O' ~+ x$ H+ o: v! G( Z& z6 K4 G: m+ W7 o3 e4 @5 d4 G
[mw_shl_code=c,true]/* ----------------------------*/: u, s- x6 g' x' e1 C* q9 s
        /* 2. Retrieves Root Product   */
& m9 T( M+ t: I! Z        /* ----------------------------*/
1 P& U8 P2 d: ]( j* h2 q        ( L* F3 S' n# y
        // Begin navigation throUGh the document => start with the RootProduct.
5 N. z4 C$ B/ ]( z        CATIDocRoots* piDocRootsOnDoc = NULL;$ l! {! O: Q7 J
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
) w& c" F0 \2 |+ B                                      (void**) &piDocRootsOnDoc);; d' L8 s3 \! o5 J) Y4 ]9 v1 [; ~. x
        if ( FAILED(rc) ) return 3;) j$ g$ `3 w% N. w- r9 e  f
        1 E3 O3 K! x6 l3 n1 [3 @& z) j1 g
        // get the root product which is the first element of root elements
: f: D" `/ F5 w3 l6 Y( f* t  X  g        CATListValCATBaseUnknown_var* pRootProducts =
% G1 F" K/ ]2 k9 k                piDocRootsOnDoc->GiveDocRoots();
; I# M$ \* y0 W! [6 w        CATIProduct_var spRootProduct = NULL_var;
5 X% l( |2 ?6 g        8 t1 P; s& g2 U" M: k
        if (pRootProducts && pRootProducts->Size())* p+ P; r# u6 ^; g; @' b
        {  
% N; Y3 @$ F0 B" x3 y; V                spRootProduct = (*pRootProducts)[1];( u5 T/ T: n0 }7 b
                delete pRootProducts;3 f" c- Q5 c+ w4 q
                pRootProducts = NULL;: n3 ]" u# k) z
        }
1 w: o  H( k" D2 I1 I; z/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
; D& {% a; n, `% E1 Y        piDocRootsOnDoc->Release();4 E1 _+ d# X) `  I: r# g' i3 X
        piDocRootsOnDoc = NULL;3 \% j4 ^0 m/ N7 A% n* X
        2 v" h4 ?% t, R1 A4 O" l
        // Get CATIProduct handle on the root product.8 ^- |9 B9 K5 G8 {. b
        CATIProduct *piProductOnRoot = NULL;( Q; M1 T* w, V0 i1 c1 M# ?+ E
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
7 l: t4 M) z6 ]1 V; F                                               (void**) &piProductOnRoot);
) |3 P* Q# o0 a        if ( FAILED(rc) ) return 3;
/ ~+ z9 z: q6 d! @# }9 X6 v6 }. p: i6 A( S* f( K
        /* ---------------------------------------*/
/ `  h# G4 ?* @; B; R* Z( z* Y0 V; z        /* 3. Retrieves children under the root   */
% O* I0 _4 i$ W  Q' x$ [        /* ---------------------------------------*/
5 f' a* |* N* B: V6 f7 a6 z       
4 C9 J' ?1 a, K: [        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;
. x( K8 z1 u% T        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;. @& {9 u" I/ g( \# ^
        5 x1 s( K: U1 a
        // then on a root product, get all the children agregated to it.5 y0 V0 A% V' D
        CATListValCATBaseUnknown_var*   ListChildren =
6 e) Y! v1 R& u* k                piProductOnRoot->GetAllChildren();+ ^1 |* W. B$ i$ |) B: X; w1 o' D
/** @anchor err_2 piProductOnRoot not set to NULL after release */ # z! O) d1 t( ]
        piProductOnRoot -> Release();; c5 o9 H4 P/ S
        piProductOnRoot = NULL;$ A: @& U; ~1 O) U% r( g3 B
        if(NULL != ListChildren)
, P5 h9 o6 {8 \& V8 ]8 h- }        {( C8 }& n( M1 Z! b8 Q, i; d: D
               
0 W: o. k- e2 ]5 w/ S                int numberOfChildren = ListChildren->Size();, W; o; l3 P4 D+ w& [
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;* b9 P. l$ m2 _& ?! T/ ^
/ \2 j( h! z% n( n4 W
                /* -----------------------------------------------------------*/
  d* [" W+ d: o3 q# O                /*  4. For each child, get its partNumber, and InstanceName   */4 d' r  e1 A( M, U
                /* -----------------------------------------------------------*/) T$ R8 k  X, a
                CATIProduct_var spChild = NULL_var;
4 i% j7 {/ n- Z* J' V                for (int i=1;i<=numberOfChildren;i++)
4 q) V4 }* A% M6 `' n6 K                {
* v) c: l2 a& b. H+ N) ~                        spChild = (*ListChildren);6 f! l% h# a6 Y  Z9 ^
/** @anchor err_3 spChild not tested before use ( if !! ) */ & @1 `4 O3 f3 n5 w9 V! C7 c
                        if ( NULL_var == spChild ) return 4;
' G/ I) T- ?9 x* v( X                        CATUnicodeString partNumber = spChild -> GetPartNumber();% ]/ l* @$ j! U$ ^' b6 i+ v; ?
                        CATUnicodeString instanceName (" ");
) e! G7 t- j; v' z0 Q: Z2 M                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
! J# t; s) k% @/ q' N, n* E9 Q                        if  ( FAILED(rc) ) return 4;4 r. j$ R! z# z; P' }7 l/ [' L
                       
# d' P2 T: r4 S                        cout << " child number : " << i << endl << flush;
/ I/ D5 M: y- Z, s% K                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
. p8 n8 ]% s- _" }: j                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
1 T/ D" V) Y; A8 D                }- v& O" ^; e* [+ g; a/ E# T
                delete ListChildren;7 U. W# B4 l# |
                ListChildren=NULL;8 W( w% a: O! F/ O& j5 L% E
        }        3 z8 p; M$ ?! ^/ T+ ^3 A
        /* -------------------------------------------- */0 o" K8 Y; s7 W( d5 M
        /*   Ends the session                        */" E4 g! C$ d( Z' V
        /* -------------------------------------------- */[/mw_shl_code]. U/ S# ?% ~1 E- {6 L3 s
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了