PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
; G1 x% @: T( k! C( y+ L+ q
Catia二次开发源码分享: 获取装配所有组件列表. \( p9 @- [5 I
' J2 h: {) \% T- Y- e: a4 |! t

6 h3 @2 F7 k. m  M[mw_shl_code=c,true]/* ----------------------------*/
# P5 S0 F/ ^6 q" @  n1 p        /* 2. Retrieves Root Product   *// D2 m; {, S: \; d5 U. g
        /* ----------------------------*/- i. o" N6 `) w7 m6 G3 c1 u
       
1 w4 n5 v/ ^6 U6 c        // Begin navigation throUGh the document => start with the RootProduct.& s  m3 z; b$ |+ p, N
        CATIDocRoots* piDocRootsOnDoc = NULL;7 k5 T% a6 @2 v. J) ]
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
+ k. t5 D- u: X" S% ^' X                                      (void**) &piDocRootsOnDoc);! T2 k' O; n' d- {0 i4 @4 c6 K) w4 x# n' p
        if ( FAILED(rc) ) return 3;9 L' y, R  m5 ?$ L0 b
        1 K' j5 n8 ^( E* [+ n
        // get the root product which is the first element of root elements/ [1 o5 f$ D1 X* p% x7 \
        CATListValCATBaseUnknown_var* pRootProducts =
- N" n9 F4 l6 o9 Z# K! q                piDocRootsOnDoc->GiveDocRoots();% w4 f5 k+ D$ m! L. A
        CATIProduct_var spRootProduct = NULL_var;
3 M3 b( H9 B  ]7 f6 f        5 |6 c8 D+ J( l, k
        if (pRootProducts && pRootProducts->Size())
' M5 J) F% R0 F4 @4 J% E4 s' i        {  4 R3 b. [5 {% j' H$ }6 l
                spRootProduct = (*pRootProducts)[1];
+ n" W  [1 O# U- W" M! ^                delete pRootProducts;' G" N8 ?( P1 e8 B
                pRootProducts = NULL;9 M9 P) L! }8 F0 q8 L+ ~9 m5 `
        }  g1 @- Y4 y) F. t5 @
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
: K# W& E1 J# |0 N        piDocRootsOnDoc->Release();
% f1 G& T0 C* }        piDocRootsOnDoc = NULL;
( v0 }# I9 a: f  D; n, _       
( P' f; \0 M3 m; F% `        // Get CATIProduct handle on the root product.
: T) U# ^8 I7 N; ]. l; i4 T! D( b4 Y( E: q; X        CATIProduct *piProductOnRoot = NULL;
+ v# `1 t. M6 T1 @# \* O6 f        rc = spRootProduct->QueryInterface(IID_CATIProduct,
0 [1 X) b: r4 O8 f& W/ @5 H                                               (void**) &piProductOnRoot);$ t+ v& H( J9 @* B1 p8 u
        if ( FAILED(rc) ) return 3;. Z2 m2 V; r- ]0 U

$ `+ W0 `' ~  X, d        /* ---------------------------------------*/) }8 {3 h/ @* @2 |# A% n  ~
        /* 3. Retrieves children under the root   */
# C7 ?; m$ K5 c, c, e/ J        /* ---------------------------------------*/- e: s; [2 ~3 V) k/ X: O* W
        : l0 k0 K: o; m5 j( P# V
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;
6 o& k% T: B3 e. ]        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
4 a  o1 j2 V* C2 f( J        2 M5 j' y$ A" `* \" {$ W" G
        // then on a root product, get all the children agregated to it.
4 g$ `7 H  [( N) V& O        CATListValCATBaseUnknown_var*   ListChildren =
% |7 i. H+ x: _7 {6 }+ l                piProductOnRoot->GetAllChildren();8 I  D) D1 n% Y4 }
/** @anchor err_2 piProductOnRoot not set to NULL after release */
' j: |6 I0 q& {        piProductOnRoot -> Release();: [* ]0 m! q% r/ Y0 {
        piProductOnRoot = NULL;" f; A/ X4 x* z2 L. r  f
        if(NULL != ListChildren)
! J3 ]. ~" K5 M! H  _$ P7 a" \        {( ?0 g- M; A1 I
               
+ r4 X  u2 L- m9 f0 j  {5 Z                int numberOfChildren = ListChildren->Size();
3 q! A7 J& v3 J                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
: d2 o  u2 p4 Z. S' {' {( i0 I; m6 z, ]' b
                /* -----------------------------------------------------------*/$ [( ?: Z- a. U/ y9 H& J
                /*  4. For each child, get its partNumber, and InstanceName   */3 w, R! S! ?: v$ P2 w
                /* -----------------------------------------------------------*/  W1 z% Q! @6 g  Q* ?! s! A2 p3 v
                CATIProduct_var spChild = NULL_var;( a/ q' V$ P! g0 e# D' F
                for (int i=1;i<=numberOfChildren;i++)
' t( [! v2 R# q                {  C3 o# c5 P$ x
                        spChild = (*ListChildren);
$ h& G- p# @1 d, t/ O$ N# E5 n- p/** @anchor err_3 spChild not tested before use ( if !! ) */
. F+ m& S8 H3 E( }! I0 A                        if ( NULL_var == spChild ) return 4;
3 ]& |4 {; e0 W& Y/ ]7 {                        CATUnicodeString partNumber = spChild -> GetPartNumber();7 @2 l6 I; v1 W$ P0 m  `
                        CATUnicodeString instanceName (" ");
% g9 g' V: J8 x                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
2 i3 G  }% `. U  f+ T# q. I                        if  ( FAILED(rc) ) return 4;; ~9 r" S' J5 w+ J4 q, K% G
                        5 A) A2 i, v( K
                        cout << " child number : " << i << endl << flush;
7 P6 B5 y5 {" p- V                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;, [  v8 C7 m  @& a& K: {7 T) W
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;5 D; ~- k3 R, `  W, A6 |
                }+ B& Q8 F  ?; k/ e: @$ W  b
                delete ListChildren;
" x+ n" V3 j/ A& H                ListChildren=NULL;/ J/ a2 t7 ]- M# b  a( M; M: s: Z& T
        }        - @1 b* N6 l8 A  O
        /* -------------------------------------------- */
9 P. m9 [! U* ?        /*   Ends the session                        */
/ m7 q/ x; ]$ t9 O; ~        /* -------------------------------------------- */[/mw_shl_code]
- G# |" }- M9 n* 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二次开发专题模块培训报名开始啦

    我知道了