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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
' T3 I+ }1 |/ [% t; O
Catia二次开发源码分享: 获取装配所有组件列表* m8 }) y# A" S9 C3 N& K8 I0 N

8 `7 N0 e$ N" _
6 y2 \) y( q! c[mw_shl_code=c,true]/* ----------------------------*/
. d* H# H# K  z' K4 u( y+ F( @& p+ T        /* 2. Retrieves Root Product   */
, \( X1 v9 C6 T6 C! F6 G5 C        /* ----------------------------*/, `* T7 L0 m5 V9 ~6 g0 Q
       
" j. i8 K( Z+ T3 i% {+ `        // Begin navigation throUGh the document => start with the RootProduct.) f( V' s+ w; Y' \4 n3 A0 l# l# ]
        CATIDocRoots* piDocRootsOnDoc = NULL;
9 }5 e- B4 e6 R+ N        rc = pDoc->QueryInterface(IID_CATIDocRoots,# [7 W2 n7 r& q* j3 T# {' @! H
                                      (void**) &piDocRootsOnDoc);
' c' b) ^9 }+ J1 S& x/ C        if ( FAILED(rc) ) return 3;# `3 ~* e" v6 u6 X, d
       
# {! B; l2 y6 {. s# d$ m+ {9 s  }        // get the root product which is the first element of root elements. D4 B4 o/ W/ C) K# ?1 O, w
        CATListValCATBaseUnknown_var* pRootProducts =
' P' n( k! a* d9 x4 J$ I# y                piDocRootsOnDoc->GiveDocRoots();
! E# P+ C6 l3 Z0 P  a. \        CATIProduct_var spRootProduct = NULL_var;# Y* @5 h4 \5 M8 ^8 H& p
        5 \: H, Q( w: s1 I+ j* y
        if (pRootProducts && pRootProducts->Size())
3 `( Y( |  _$ y5 b( N" U        {  0 ?+ N1 H  [3 _$ _
                spRootProduct = (*pRootProducts)[1];) |; e& G3 n1 X# s" I0 ]6 Q
                delete pRootProducts;; s5 K0 a. X2 P* V+ k" i  l$ e
                pRootProducts = NULL;
# B, A' {4 @' d        }+ Q. E! ]) Q% v2 Z3 r
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */   c9 z1 n5 c& _0 |: ~
        piDocRootsOnDoc->Release();
1 N* G5 |" u7 F$ w. c6 J6 T) [* M        piDocRootsOnDoc = NULL;
" `$ k$ B' B7 l, e! v: r& n% A       
3 @* N: K# g" f* t* g$ X        // Get CATIProduct handle on the root product.' v# }, B& G' ?+ |* G
        CATIProduct *piProductOnRoot = NULL;/ i9 }, B  g' k4 X3 _
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
: W  d) O! O4 E; E0 D                                               (void**) &piProductOnRoot);! H& A( S/ ^3 L2 T& a
        if ( FAILED(rc) ) return 3;
- [" u( B/ @6 ^! D& J. l: D, o/ W+ U9 I. y3 P0 A5 y
        /* ---------------------------------------*/
9 C! s3 y% H' V" \1 u6 }! V( s        /* 3. Retrieves children under the root   */
# b. O* R3 V7 f0 Z: R% D        /* ---------------------------------------*/1 j: F& l/ I$ ]6 \2 s0 j
        2 g, f3 K4 m% Z2 P
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;( T4 n/ \9 O9 f( D1 L/ f
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;! E2 J2 Y5 }  V1 x9 j  v
        7 e8 u- G8 p. b) F3 ]) _* K
        // then on a root product, get all the children agregated to it.
; i/ y( l  F5 a& ^, G, h        CATListValCATBaseUnknown_var*   ListChildren =$ F$ D) k3 v2 F8 R0 C
                piProductOnRoot->GetAllChildren();
& w% B$ X% y% j+ A  k, }: @5 s/** @anchor err_2 piProductOnRoot not set to NULL after release */
$ ]# L1 ]) s8 S0 o8 ?: N" G        piProductOnRoot -> Release();
( c$ @- G1 [: ]' G+ A        piProductOnRoot = NULL;0 Q# n$ w3 W% S, C/ h" |1 f
        if(NULL != ListChildren)
. p: S) }5 w7 \) W        {
1 X. Z3 @+ _4 v) C( C$ q1 x( v3 g8 Z                9 M2 B& [& ^5 k2 \
                int numberOfChildren = ListChildren->Size();
5 M7 H! n2 u5 q4 T                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
- {( `8 T+ I7 K
6 w& e2 R# l% x5 ^7 \) r                /* -----------------------------------------------------------*/
/ g% S5 h  W7 H& G; M                /*  4. For each child, get its partNumber, and InstanceName   */
+ }; t; e% x' Z0 B                /* -----------------------------------------------------------*/
8 _* C' g0 l+ I                CATIProduct_var spChild = NULL_var;# e  d2 G" ^7 N1 {
                for (int i=1;i<=numberOfChildren;i++)8 K7 }; M& `! ^' M" f
                {
5 g8 s4 {  P- t$ E/ R. I; G                        spChild = (*ListChildren);5 I5 A( l, x" Y1 D
/** @anchor err_3 spChild not tested before use ( if !! ) */
* [+ s6 V& k8 j" p, K0 P, C# l7 J                        if ( NULL_var == spChild ) return 4;( d* {( t) l& A% u
                        CATUnicodeString partNumber = spChild -> GetPartNumber();& o, M( B& k( ^& X# S" B
                        CATUnicodeString instanceName (" ");* P. }% B  |  z2 p2 {1 L- Q
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
1 @4 x. f3 r7 p) D0 D, ]( c                        if  ( FAILED(rc) ) return 4;
2 s, N; u! M2 O& ^7 [( f& r$ O, {                       
- `# R8 E7 j- D& c# `. {5 r# b                        cout << " child number : " << i << endl << flush;0 A. k$ B% j/ l& x; A: Z
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;* l) v0 t4 R: H+ w/ ^
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
& t: R+ s4 N7 t7 K. Z7 z                }7 F' f: w8 |- u: Q  ?% {
                delete ListChildren;
0 d; ]' L; O6 e                ListChildren=NULL;4 {) \: W9 |3 Y+ ?% R/ z2 E
        }       
* f2 F& ]; e3 z4 o        /* -------------------------------------------- */
. V& _* s/ K+ I3 s" e8 t        /*   Ends the session                        */9 p6 D% b2 Y% {4 M6 p  G, k5 I/ T
        /* -------------------------------------------- */[/mw_shl_code]2 O2 \- c( x9 `5 J+ _0 D2 ?$ w4 X
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了