PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
5 F6 w$ g9 w3 z& f" z! \9 t
Catia二次开发源码分享: 获取装配所有组件列表
/ W/ C/ e* b  i1 s5 J  o9 i, ?$ x$ H, t* D# e3 `/ w; x! E

5 ^2 r% j8 }; ^1 j* l+ g[mw_shl_code=c,true]/* ----------------------------*/6 C; g" W+ s# `! e" G9 Y7 N
        /* 2. Retrieves Root Product   */
4 u9 v0 r4 N1 q3 u2 H        /* ----------------------------*/
) n! n9 d# g2 q7 u+ r2 I% a. O       
. c6 S0 ]9 t$ T; [+ q: b        // Begin navigation throUGh the document => start with the RootProduct.
- P5 E3 E0 Y2 e4 P* `        CATIDocRoots* piDocRootsOnDoc = NULL;
$ m7 S; J4 L+ h; H8 n8 m( A! Z        rc = pDoc->QueryInterface(IID_CATIDocRoots,+ t% Z9 g7 M7 U9 |" `* r! [
                                      (void**) &piDocRootsOnDoc);- ]  X* o* k9 K% \. G; v, ^
        if ( FAILED(rc) ) return 3;4 T) G  W1 P" O
       
" e1 E: K, @0 p) P( P        // get the root product which is the first element of root elements
5 t8 k: b: O4 v- x2 e& N" I/ X        CATListValCATBaseUnknown_var* pRootProducts = 1 j4 N6 k2 `0 G/ o: y1 @
                piDocRootsOnDoc->GiveDocRoots();
/ T: u# G$ T% [" j        CATIProduct_var spRootProduct = NULL_var;
9 H% D0 C3 I; p       
' R+ Q' f+ z3 Q        if (pRootProducts && pRootProducts->Size()); n1 T" j) R9 j% Z
        {  
% [; {/ l6 P- J7 y  s" O                spRootProduct = (*pRootProducts)[1];2 Z' {6 {: N- W- a
                delete pRootProducts;
) g6 J$ u- m$ M+ {9 N; p                pRootProducts = NULL;1 B( g2 h( _- b( ]9 l
        }
& R& ?3 [* o: s9 u6 [, b8 w! \6 b/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ 1 m5 e: N; z( X. S: \, ]% T
        piDocRootsOnDoc->Release();( `/ q; ?+ W0 R6 ~: f, q
        piDocRootsOnDoc = NULL;9 p0 [, T+ N& I* V+ K/ U" @' |1 g
       
# `8 D8 N& z# s% a, h4 H        // Get CATIProduct handle on the root product.
3 ^- p' h8 D: J' V0 W        CATIProduct *piProductOnRoot = NULL;
0 {/ o, X! w2 a, l& U5 M# g        rc = spRootProduct->QueryInterface(IID_CATIProduct,8 o7 `5 E# l3 r* L* H+ n/ ?
                                               (void**) &piProductOnRoot);. u$ R) `# c" h3 o4 k
        if ( FAILED(rc) ) return 3;
0 s% K" ?4 g% U+ S* U$ g  X, n
0 l) K) ?- ]+ q$ h        /* ---------------------------------------*/: u! J3 j1 ]5 ~# |1 F
        /* 3. Retrieves children under the root   */8 H" F+ G: R6 h, z. Y' f
        /* ---------------------------------------*/
* r9 r- f$ |- Z- W       
9 V1 g6 v0 K/ i9 \2 K/ f# n( v' t: E        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;, W2 b/ ?' E0 q  W  G4 ^7 y
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;/ C5 P: r* K8 z# k+ k3 @) E
        - ]1 {  G3 w/ E2 I
        // then on a root product, get all the children agregated to it.
; T3 }- e1 E. `2 t        CATListValCATBaseUnknown_var*   ListChildren =" u6 M; ?& z; l/ e; i, `& [
                piProductOnRoot->GetAllChildren();4 z9 W- I6 \: n! }) o
/** @anchor err_2 piProductOnRoot not set to NULL after release */
5 d! @8 T7 b/ ^4 j/ g) R" A        piProductOnRoot -> Release();+ I2 E, c  k3 U: y
        piProductOnRoot = NULL;6 j2 `* Y& j) Q% b# J; S( ^
        if(NULL != ListChildren)
6 B$ }3 @- _1 Z        {: s" o* m/ P: ]
               
* Y1 D2 I" N9 ?2 t7 K9 ^) e! c                int numberOfChildren = ListChildren->Size();
0 A* x+ O4 n6 _- Z- a+ V; C( W                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
* h" Q. l% k+ A" X3 U+ G" T% T+ _  ~' W& J% v
                /* -----------------------------------------------------------*/
/ e, f8 k& L: K: S4 M, ?                /*  4. For each child, get its partNumber, and InstanceName   */
3 F+ D8 N# h' w7 }$ e# D2 _                /* -----------------------------------------------------------*/
9 h0 E' N- x; x9 X                CATIProduct_var spChild = NULL_var;7 g1 _1 n# @8 k3 C- H
                for (int i=1;i<=numberOfChildren;i++)" y) K" O  w7 [% `3 a# r5 c, o" R
                {
! i: p# p, @4 d* O+ r                        spChild = (*ListChildren);
% T* E* [+ h2 H) s' Q* W( Z' r/** @anchor err_3 spChild not tested before use ( if !! ) */
* U& H1 m5 a1 ]! e                        if ( NULL_var == spChild ) return 4;7 S+ h1 L2 ~, q" }" f; ^4 h
                        CATUnicodeString partNumber = spChild -> GetPartNumber();
3 @6 x  ]) ^4 }; C                        CATUnicodeString instanceName (" ");. I3 I5 F  M0 N; P
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
; k) h0 W+ j0 S" R- A) K2 d                        if  ( FAILED(rc) ) return 4;  m% }/ D* Z5 }2 A; s7 Q
                       
& ?9 n4 S0 F* ]3 g& d                        cout << " child number : " << i << endl << flush;6 j; r9 }  A9 b9 ], |+ [5 ?
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;; O: w& g1 D: B7 x9 X) T
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
1 ^; P3 r" q7 `7 I                }+ Z* g) h6 |) G2 G5 L7 A
                delete ListChildren;
4 |9 M1 [# T  e6 L# E, V$ ~1 q% ?* z* o                ListChildren=NULL;" {2 `2 u9 f) s. v% j- z5 ]
        }        0 L. t2 @. N' x
        /* -------------------------------------------- */% a, P0 R3 `2 S2 ~0 P/ R3 P% @1 n
        /*   Ends the session                        */9 G* K- l* N# a1 h0 h2 F; O& U
        /* -------------------------------------------- */[/mw_shl_code]
6 q% O9 N" y+ U+ k1 g9 c3 Z
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了