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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

; x7 [5 c0 C; f/ O; N* P6 nCatia二次开发源码分享: 获取装配所有组件列表0 \1 k& P% C# }9 w  ~& Y

+ O! O! N8 u& I2 K1 H/ w2 L+ O7 F2 u+ G
[mw_shl_code=c,true]/* ----------------------------*/, b1 M. d2 c5 y9 z$ Q5 i
        /* 2. Retrieves Root Product   */: P1 \0 x# u# m/ U# J& W. A
        /* ----------------------------*/
' f+ M8 I0 }9 [- r" i4 g        1 g0 q$ E# U! w5 a/ I4 k# }
        // Begin navigation throUGh the document => start with the RootProduct.2 ]% y3 F* i2 m* }  D5 ]7 ~
        CATIDocRoots* piDocRootsOnDoc = NULL;( p; g- p: ?; @6 D2 d& P& [$ A3 v
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
/ I) i/ [) o( G8 N* }1 A. S8 u2 W                                      (void**) &piDocRootsOnDoc);% V; Q; E8 T, B$ k- j" w/ d; K" Q
        if ( FAILED(rc) ) return 3;
8 V5 Y" T* G6 h& ]! l& C        " l- n  X5 y" I- e  I: H! A
        // get the root product which is the first element of root elements
( e$ a7 B# ?1 F1 T" x  X, u        CATListValCATBaseUnknown_var* pRootProducts =
! r! g3 h) [. ^  k+ S2 @# d+ d; J4 I% g                piDocRootsOnDoc->GiveDocRoots();" ?, q$ g- D% }' \; x$ P9 p* Q
        CATIProduct_var spRootProduct = NULL_var;1 u" x; a; e6 w* U6 m0 N: o6 v
        8 c* P$ d7 S9 w. G
        if (pRootProducts && pRootProducts->Size())
7 x6 A4 ^' t) q0 z( d* Y        {  ! s: Q2 k: Z7 d& \, C6 j
                spRootProduct = (*pRootProducts)[1];* @2 `6 U, ]7 H  m$ q) S
                delete pRootProducts;2 m4 O* r1 K6 h
                pRootProducts = NULL;
; g* a' p- w4 n. A- ]8 n! {        }7 V% R' n% {! X% m2 l" U
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ 0 K! k4 t* ~5 `' W. G
        piDocRootsOnDoc->Release();
$ J  {7 A, w# u        piDocRootsOnDoc = NULL;1 \1 J: v8 G7 O2 Y) z6 d
       
% R: T6 K: w1 O% S& N        // Get CATIProduct handle on the root product.
  ]! o& w/ ~% D& C1 `        CATIProduct *piProductOnRoot = NULL;
8 p' ~5 r1 q3 n# c& w& g: D8 {        rc = spRootProduct->QueryInterface(IID_CATIProduct,5 p) e5 n* I' D  J. C1 d
                                               (void**) &piProductOnRoot);) x1 A; {0 K1 |% a& l/ T, L- j
        if ( FAILED(rc) ) return 3;4 \" {8 k( ]2 z- p6 U7 T
+ r+ ~; t& Z4 p( v
        /* ---------------------------------------*/
; S0 A& p  B8 S$ p9 K        /* 3. Retrieves children under the root   */$ J% F: V3 ^9 q- H9 F. L
        /* ---------------------------------------*/
& f% g3 c8 [6 e- y/ k3 H7 O0 C       
9 ?, k' }2 o- a1 q" u  v- c* I        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;0 x% i, Q$ F  z5 m
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
- w. ]0 M9 j. Q' A& B# J' c       
  {  M) S; k, V        // then on a root product, get all the children agregated to it." u: h  u( f( I# l' N* {
        CATListValCATBaseUnknown_var*   ListChildren =- X8 I4 C( |( o% H1 Y6 K$ @  H
                piProductOnRoot->GetAllChildren();
0 i0 M2 N9 D8 k/ Z/** @anchor err_2 piProductOnRoot not set to NULL after release */
- g8 p- A# U, V% c/ q* l        piProductOnRoot -> Release();/ @0 r- w' G& s' ~
        piProductOnRoot = NULL;+ n, R/ w4 W- Z* t" Z. ^
        if(NULL != ListChildren)
, r! n8 X3 x8 d; ?' O- c0 S. z& z        {
8 s2 n2 k8 |0 f! U                : F& g$ z  j; F, y2 _9 Q
                int numberOfChildren = ListChildren->Size();
$ D% E& B0 |, N& N                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;- D+ X. n% l6 x5 d0 v

; W, [0 Y- I$ a' ~5 H% {/ _8 l                /* -----------------------------------------------------------*/
; p7 ?% p! `) V) P/ C                /*  4. For each child, get its partNumber, and InstanceName   */
9 P' |% N5 L' m6 ?                /* -----------------------------------------------------------*/& L/ p; b* g3 U3 y& ]0 Q/ o0 K7 E
                CATIProduct_var spChild = NULL_var;
' {$ k8 I5 [2 O3 D8 Y! f3 I" H! V5 _                for (int i=1;i<=numberOfChildren;i++)
. B* \6 V( o! S3 P( z                {
# S3 M, o1 m3 m+ z                        spChild = (*ListChildren);
# m" f! p3 q$ I- ^/** @anchor err_3 spChild not tested before use ( if !! ) */
0 X+ R" M6 e. Y1 c4 I: N2 B                        if ( NULL_var == spChild ) return 4;
; H+ R% \- \+ W9 n                        CATUnicodeString partNumber = spChild -> GetPartNumber();: ?$ I3 A% V+ Q1 q$ H3 s
                        CATUnicodeString instanceName (" ");
( `; R& Y' r1 D- N! K8 |" J                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
' x* h# b4 Y7 e. i/ s# ~                        if  ( FAILED(rc) ) return 4;
9 v9 g- e' a$ p/ N                       
. y1 _: }  y- w/ a* a% H                        cout << " child number : " << i << endl << flush;
& ~& Z: c3 S- N7 ]( i, Y                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
( \  G  H  Q; s7 w4 S$ A                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;
# v6 D( L% q% J0 q                }8 G* B2 a" C0 q* @) M$ D
                delete ListChildren;0 O+ F7 S/ r4 J
                ListChildren=NULL;9 z( m0 [8 j! M: T3 |) _9 ]
        }        ) [; M9 Y- L5 `$ u& ]
        /* -------------------------------------------- */# M* Y. ^& u4 [4 I) u5 Q
        /*   Ends the session                        */
' K4 T) Q, ?0 t; v        /* -------------------------------------------- */[/mw_shl_code]' b4 S/ S( I2 W& s) m- u
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了