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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
3 W9 H3 Z0 w- e+ T0 }4 Q0 }( |( i
Catia二次开发源码分享: 获取装配所有组件列表
9 {5 D# }  ^6 p9 z7 Z) I( _" `& O$ @' z2 w+ Q5 S/ ?. H* o
8 |8 U' H) V; w5 l/ M9 d/ @
[mw_shl_code=c,true]/* ----------------------------*/0 T* j7 G7 i8 Q6 v; q9 H; x6 j3 t
        /* 2. Retrieves Root Product   */
1 f- P' F( c0 [) `' a$ W/ p/ U        /* ----------------------------*/
) x3 W  y; _6 S2 U        , q4 X5 l( m& B8 a3 r
        // Begin navigation throUGh the document => start with the RootProduct.
! k# `. }  ~3 r! v        CATIDocRoots* piDocRootsOnDoc = NULL;$ s4 G; U4 p( R) u* h
        rc = pDoc->QueryInterface(IID_CATIDocRoots,
: c3 B& P: l6 _3 [, o                                      (void**) &piDocRootsOnDoc);5 B( I- E( ?9 K/ l7 h
        if ( FAILED(rc) ) return 3;8 @/ o& r& q& k5 V+ k  W: I
        , N# @* x4 _3 Y. X( r$ C
        // get the root product which is the first element of root elements! X, K+ @! j  F* l+ i  \2 b$ p0 X
        CATListValCATBaseUnknown_var* pRootProducts = " H. @; ~6 n8 h7 `
                piDocRootsOnDoc->GiveDocRoots();0 }* q3 [" O/ ~" Y
        CATIProduct_var spRootProduct = NULL_var;
, e& m+ P( y/ w3 Z) ~/ j       
9 ?, C6 v  `3 @6 [        if (pRootProducts && pRootProducts->Size())
! I1 c7 M1 N' j& M, I( i        {  
8 B2 W4 x8 T5 i2 I                spRootProduct = (*pRootProducts)[1];
0 x. d' |$ h* Y, z. \9 ?. ^- b2 Y, n$ }                delete pRootProducts;
- y( E* `7 x' C: q                pRootProducts = NULL;
. k  l8 g: P* h2 P6 E- p$ M        }
5 P% @" \. L; ?; }4 t5 p. b' H) y+ {/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
! f( Z, K1 b  c8 e  k        piDocRootsOnDoc->Release();6 k, y) A. d+ p; L& z
        piDocRootsOnDoc = NULL;
1 X, A+ |5 Y( ]8 i        / O$ o; J! g3 k0 ]1 q2 [  _
        // Get CATIProduct handle on the root product.
: _6 d. a- c5 ~8 l6 b% j, ~        CATIProduct *piProductOnRoot = NULL;7 {: u4 Q# ]( m2 ~
        rc = spRootProduct->QueryInterface(IID_CATIProduct,
$ k" o7 D# K0 E/ e" r4 W                                               (void**) &piProductOnRoot);1 t* m9 W* o  |) |0 b  r' b+ i! o* s
        if ( FAILED(rc) ) return 3;
! D/ e9 v7 a/ k7 L- P7 Z+ |) g) E. ]' P8 p0 r% h$ ^: I
        /* ---------------------------------------*/
5 A( ~  W* Y( f% F+ s# c        /* 3. Retrieves children under the root   */
) ^9 t  ?- k! Z7 Z  K; `# u* J. U2 R/ o1 \        /* ---------------------------------------*/
/ r4 f9 Z, W( n0 j) e7 f        % k5 _0 j% m1 n  |- s  Y
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;6 t, i1 X! q  @1 C4 x) b: R, N4 \! N
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;
" g; o8 {: C! D  r  r       
, b# r! H$ X% a# o        // then on a root product, get all the children agregated to it.. k1 x; f/ r% x; t0 ?
        CATListValCATBaseUnknown_var*   ListChildren =
3 Q6 y2 q) V: F( H6 z, n) n" ]                piProductOnRoot->GetAllChildren();
2 X- x0 D& H  r( Z. T! \/** @anchor err_2 piProductOnRoot not set to NULL after release */
. l3 X0 F. V5 o5 R+ L: H/ w        piProductOnRoot -> Release();
+ I  Y3 C3 Q# ]' N% y        piProductOnRoot = NULL;
( z/ J; |+ {" W4 \        if(NULL != ListChildren)) z- _$ Q- R0 h& \# \7 a2 v
        {6 f# f: h2 U2 E% z3 c
                . }/ Y1 L# K" \6 y. g) f+ j
                int numberOfChildren = ListChildren->Size();
6 O) \" e9 ~* D% A3 e# D                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;8 s, a. ^( x: A8 s9 C

& D, o! l# ?7 |/ j. ?( H4 W6 q                /* -----------------------------------------------------------*/. b  b" q( f" s! L% d1 @9 w' l
                /*  4. For each child, get its partNumber, and InstanceName   */
8 X# T3 {4 |8 ~                /* -----------------------------------------------------------*/
, f2 g) P, M6 h8 P) j                CATIProduct_var spChild = NULL_var;
% d" l& t7 D) y                for (int i=1;i<=numberOfChildren;i++)1 h. m, k+ e3 A1 V( S
                {6 T# }3 b5 O! Z+ X
                        spChild = (*ListChildren);
' l* S- o& W7 h/** @anchor err_3 spChild not tested before use ( if !! ) */
/ b# ]5 u( i2 E0 l                        if ( NULL_var == spChild ) return 4;6 E4 B: R" K0 E& J8 r: U
                        CATUnicodeString partNumber = spChild -> GetPartNumber();
/ v( |% ?( @9 ^! z                        CATUnicodeString instanceName (" ");
& i6 D5 x) z8 q                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;9 W9 g: y" N* O9 E" J& M
                        if  ( FAILED(rc) ) return 4;& @: \( P: H6 `! v3 e+ N
                       
0 _" S. o' j6 C7 ?" o* z                        cout << " child number : " << i << endl << flush;6 j; H8 c, F5 e4 j5 t5 W
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;
0 h1 ~1 y$ l; t                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;& W& ?9 v7 ?# z
                }" s! }5 k4 j- G+ J9 u! m
                delete ListChildren;+ [* o. L) }% W7 h' w/ L; a  W6 _1 z
                ListChildren=NULL;
5 V8 e* ^- C! _! g        }        & X8 l. I5 |; b, h* o, t- i2 `
        /* -------------------------------------------- */
( K8 U- U5 z; q/ B) D( f& I6 p        /*   Ends the session                        */
" @! N: E% S8 A        /* -------------------------------------------- */[/mw_shl_code]9 H5 M8 ?: X- g& w! E2 I5 L' q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了