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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
2 c8 {! T: z% Z
Catia二次开发源码分享: 获取装配所有组件列表7 \$ ?9 J7 }* A% q( n3 C

# I- R) \/ S6 {6 ?5 z( B3 W) }3 Y0 a( i! `* ^9 w4 j3 f/ ]
[mw_shl_code=c,true]/* ----------------------------*/
/ o+ Z% ~' n* G9 e6 O' N+ O9 V        /* 2. Retrieves Root Product   */
; Y% G- O: H' B' p$ q: f        /* ----------------------------*/# d: y* ~- G! c" }- w6 w9 k
          C& ^( ^3 p& _/ O8 m- h1 j
        // Begin navigation throUGh the document => start with the RootProduct.
4 E: B2 |- Q: ~3 ]+ E        CATIDocRoots* piDocRootsOnDoc = NULL;. X9 F$ m2 q' }/ _
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
( p. p  {# }6 x6 @( _% a: W5 d- p                                      (void**) &piDocRootsOnDoc);
' R. I# [: m0 P6 {- \/ t        if ( FAILED(rc) ) return 3;- ?% r) X, M$ z. i) u
       
9 r" }; `( |+ @" X2 f6 E5 K        // get the root product which is the first element of root elements
( ~' c7 c) h  x, h! v8 J8 B: k        CATListValCATBaseUnknown_var* pRootProducts = . _1 U* ~% u: Y6 z
                piDocRootsOnDoc->GiveDocRoots();3 A0 E; W; Z7 E: a2 C/ I2 g0 r2 J
        CATIProduct_var spRootProduct = NULL_var;
' b6 s1 a& U- k' S+ s7 o2 M0 J       
! k, T. i. E% H6 U( e% S        if (pRootProducts && pRootProducts->Size())2 b0 f5 P1 x; d- G/ ?- x: F% X
        {  8 _* P: D( K9 @9 \5 I
                spRootProduct = (*pRootProducts)[1];
  q* W8 g/ |) T( k                delete pRootProducts;) j8 h1 t& A* ^! i  H5 `% n& M+ a
                pRootProducts = NULL;9 @9 m; O& n$ T- X) W" h/ Z
        }# z' @$ T) {/ q5 V9 u: g4 n6 U
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ 9 |/ ]4 D7 h- k1 ]5 N" x0 @
        piDocRootsOnDoc->Release();
# b+ E6 _' R7 I" ?        piDocRootsOnDoc = NULL;
/ q% X' i1 s9 Z. U; u       
8 S) H' x" |9 q0 i2 n/ r7 W        // Get CATIProduct handle on the root product.
1 G, n) m8 ~9 u+ X( a        CATIProduct *piProductOnRoot = NULL;& R1 J. n& c) R' V4 m: @5 d$ {
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
9 o6 Y' a4 V5 S$ h6 x                                               (void**) &piProductOnRoot);
! Y* J8 t( R4 V9 }" f        if ( FAILED(rc) ) return 3;* K) j1 X. P) ]/ F) A" B3 Y6 ^9 V

! _% @7 n6 v# R# c        /* ---------------------------------------*/
! y  |" K5 d  U. f! ?& Z3 x+ y        /* 3. Retrieves children under the root   */$ a, D3 K0 y3 K  f; b, \& N: f( N7 X
        /* ---------------------------------------*/
# t! M7 l  {5 j! J2 |        2 r8 A8 z" c8 w, K/ {$ L- `. ]! K
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;( l, R; A, m; _% x
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
& B9 \. E2 U3 @1 M+ m- q) [        ! {" i; q8 H+ D4 [0 C1 C/ h
        // then on a root product, get all the children agregated to it.5 e* p  h) J1 l& m1 {
        CATListValCATBaseUnknown_var*   ListChildren =
9 m; x  U: u5 ]+ A* T) o' K+ V5 b                piProductOnRoot->GetAllChildren();& g3 q  I1 E. f' g$ f) r0 E
/** @anchor err_2 piProductOnRoot not set to NULL after release */ 0 b' u9 I* C! E2 _- y
        piProductOnRoot -> Release();8 G0 T5 {$ B0 f" Z& C
        piProductOnRoot = NULL;8 f" S# k2 H" l6 D4 e1 T
        if(NULL != ListChildren)
- d% F( X8 B5 k        {
# n. D9 C+ R9 L+ ~: c                5 W. r' h, b* l
                int numberOfChildren = ListChildren->Size();( [& H  X0 e6 M) }
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;7 \6 E5 S- d( W% W  N5 _

2 N+ V6 O7 t2 p1 [                /* -----------------------------------------------------------*/: p# A/ V. P% f) d, a, P
                /*  4. For each child, get its partNumber, and InstanceName   */
3 K" @5 O: H" S% M                /* -----------------------------------------------------------*/
  q8 P* h0 q( p" Z( s. z                CATIProduct_var spChild = NULL_var;
+ N; v3 c! l- R, ^/ d' V                for (int i=1;i<=numberOfChildren;i++)
8 g! v6 ]( O, e% P; k                {. F/ C7 O5 m- B+ }
                        spChild = (*ListChildren);1 X, I) E5 U6 ~4 N
/** @anchor err_3 spChild not tested before use ( if !! ) */
8 Z8 g3 a" W# g                        if ( NULL_var == spChild ) return 4;. v( T" S9 S! A4 F& _8 _
                        CATUnicodeString partNumber = spChild -> GetPartNumber();
1 E7 M' n1 ?0 A6 r                        CATUnicodeString instanceName (" ");6 T' q- v1 [% m3 v4 r+ I
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;# g: M, u- J! ?( |* }6 w
                        if  ( FAILED(rc) ) return 4;
3 o- ]1 t5 j0 ^, D3 n" F7 t                       
2 Q( i2 z9 f" @) e; B                        cout << " child number : " << i << endl << flush;
2 e; R; N! u5 `! ?9 f5 F+ z% m1 U4 F                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;9 i% k7 [7 ~; |: Z/ D0 q& j
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;  i, C; H! V; Q/ {1 W6 s
                }8 p0 N, ]% M! P. }2 g+ G
                delete ListChildren;- Y: \; t0 t  B4 U0 ?. V/ `
                ListChildren=NULL;# `: x! p$ n, A* P
        }       
) z$ w$ T) G9 Q5 L; G        /* -------------------------------------------- */
6 x- z. W& h' w( V        /*   Ends the session                        */
) w2 w* L- N/ a7 d) s- P        /* -------------------------------------------- */[/mw_shl_code]5 U8 W, A/ Z) x3 o+ g# y' H
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了