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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
$ q8 D/ {  E; Y% W3 w" u
Catia二次开发源码分享: 获取装配所有组件列表
1 k3 m- t$ A" w: h) r; I, K  T% Q  e2 |
3 @/ x4 Q( E. V
[mw_shl_code=c,true]/* ----------------------------*/
* [4 T! O/ u9 Q* D        /* 2. Retrieves Root Product   */- A! ~; S6 D. P9 I: _
        /* ----------------------------*// ~1 h5 s! t% l" N3 z4 n5 d# O
        . h, U/ T! q7 K
        // Begin navigation throUGh the document => start with the RootProduct.
3 y2 J5 J) a) I$ b2 @        CATIDocRoots* piDocRootsOnDoc = NULL;: l6 F. o3 M0 f- g0 k
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
- P2 a. L" s" W6 C( J3 S4 P" [                                      (void**) &piDocRootsOnDoc);2 Y5 _: I( `3 [: B9 F
        if ( FAILED(rc) ) return 3;: ?# J  y( t, F
        ) o# B$ ^1 [. i3 I* i
        // get the root product which is the first element of root elements
) p. _! @) n  M$ w' D) Z        CATListValCATBaseUnknown_var* pRootProducts =
3 \4 c$ d* A5 U                piDocRootsOnDoc->GiveDocRoots();2 M( s7 H' M8 D- X! X7 I+ [
        CATIProduct_var spRootProduct = NULL_var;
3 c4 @9 ^: t/ o, H6 {/ h        $ Q1 O/ O/ c% C! _2 ?- x- e$ d+ h+ V0 y) f0 f
        if (pRootProducts && pRootProducts->Size()), l" H* D+ u1 G7 w& n+ }5 c
        {  
, S. e0 j# \2 w( `; U                spRootProduct = (*pRootProducts)[1];
5 l% e0 y! b( K7 W+ e% F1 `! G                delete pRootProducts;! ?" N" P+ S& u4 M( m. T1 Y
                pRootProducts = NULL;" h- T. b; m! B% ?7 P
        }3 f" M" h3 `0 e) F! R* x4 {
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
# X& T) c% p5 c1 ~/ w  _. K, D        piDocRootsOnDoc->Release();
/ i' N6 ^% Q3 G& p! _1 C. h/ s        piDocRootsOnDoc = NULL;7 Q' O6 P. L6 J$ B, ^
       
4 T1 }. i( E+ G% V" [2 }# q8 z; G        // Get CATIProduct handle on the root product.( n4 P1 _7 s- [- V* Q# N
        CATIProduct *piProductOnRoot = NULL;
/ u- Q: E4 O' t6 Y6 v        rc = spRootProduct->QueryInterface(IID_CATIProduct,
+ ?9 o8 ~5 x2 G4 B  X" B                                               (void**) &piProductOnRoot);( b) \$ u7 t$ @% b0 Y  s
        if ( FAILED(rc) ) return 3;
' W- X  Q* `7 F; m
6 o) i" t! v) H7 {        /* ---------------------------------------*/
1 O0 c7 @* {% U& ]- d7 C        /* 3. Retrieves children under the root   */
7 _* T: k0 A. K% O& n% T        /* ---------------------------------------*/
% q' R" a" I# l7 o        ! ^! f$ e& F% K5 Q* Y/ V) R
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;! ]# }2 i9 Q5 T# y
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
% m3 z6 u3 L. P3 n. u, E       
6 q) ]5 k% N2 Q$ i3 ~: p        // then on a root product, get all the children agregated to it.) s& m) H% W3 \) Z6 U/ d4 R) f' |+ k
        CATListValCATBaseUnknown_var*   ListChildren =
9 H' a5 z( g5 L                piProductOnRoot->GetAllChildren();
; @6 P9 b9 J, o9 p0 G/** @anchor err_2 piProductOnRoot not set to NULL after release */
: g8 g1 G0 @! R* j* N4 ?- h2 n        piProductOnRoot -> Release();
) O2 L7 \6 {: J! C* Y1 q        piProductOnRoot = NULL;
8 a' I+ A' t/ H  t1 H  O        if(NULL != ListChildren)
8 U7 r' O7 [: c# `        {7 W! \' W' [9 w
               
* x5 Y0 X- F: c3 H4 i+ Q                int numberOfChildren = ListChildren->Size();
; }( t+ S9 I" R4 F# c                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;$ J( n; w" g% k2 G2 ?) I

1 }: y% o6 B* ^$ L8 h* |6 y/ v                /* -----------------------------------------------------------*/; R/ z0 T) X1 V# H9 p
                /*  4. For each child, get its partNumber, and InstanceName   */
; I* N# n0 ]0 G                /* -----------------------------------------------------------*/; D( q$ u( b+ H% T" p
                CATIProduct_var spChild = NULL_var;
- {+ [8 p+ ^& {# N8 A. R: y                for (int i=1;i<=numberOfChildren;i++)! E7 T9 t! h; j) H
                {
) M7 T" r8 A# L                        spChild = (*ListChildren);
" j2 }  |6 }) g2 P% k0 m/** @anchor err_3 spChild not tested before use ( if !! ) */
& ~, A  m4 H# i. o2 t% J# b. R                        if ( NULL_var == spChild ) return 4;
" v# V' |+ |3 g; T/ X9 j% Z+ @9 }2 \- r                        CATUnicodeString partNumber = spChild -> GetPartNumber();
$ X1 a+ d  H6 e) O$ ~                        CATUnicodeString instanceName (" ");3 M* Q5 {  ^7 A' W5 b+ z5 [$ S
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;1 \% K) V0 \/ P% v& I
                        if  ( FAILED(rc) ) return 4;
3 h# [  j) S8 G. U                       
  r7 m  m) h; l' J; _3 z                        cout << " child number : " << i << endl << flush;
% O4 b3 P( @# B+ z% w                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;" c' E2 a! ?! p, |3 w; F
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
% h. y/ w$ S+ J' A8 I                }- B# N8 G% o/ o, }
                delete ListChildren;
" ?) p3 y4 R& e2 R) ]; x4 D7 m                ListChildren=NULL;& E% I: L2 F) n- x. W: G. M
        }        - u8 ~& \  \3 n3 t, `
        /* -------------------------------------------- */
2 l& n4 |0 j" [3 Q9 f        /*   Ends the session                        */
* B- n; ]) v& ]& f# ~  l2 M3 z% W        /* -------------------------------------------- */[/mw_shl_code]' H& r2 z' q# K4 }; I' d
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了