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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x

  _6 D" z1 f; [5 o1 `) ACatia二次开发源码分享: 获取装配所有组件列表
' ?0 |# ~& z1 P4 {8 j
" S9 k( c! J/ e* _. m# @. U3 r/ H& F
[mw_shl_code=c,true]/* ----------------------------*/
( Q8 U4 q7 K8 z/ R! `1 |& M        /* 2. Retrieves Root Product   */
2 F" h- L# H) }- A) Y        /* ----------------------------*/
9 a$ [  Y) \  i8 L# g        0 t  F4 Q7 B4 j% b- D: P, m! G
        // Begin navigation throUGh the document => start with the RootProduct.
; a# u: j/ z7 P4 q        CATIDocRoots* piDocRootsOnDoc = NULL;
  o' V* \- Z/ q2 o5 D        rc = pDoc->QueryInterface(IID_CATIDocRoots,7 @9 y/ H! z7 W, u6 b
                                      (void**) &piDocRootsOnDoc);
6 e3 `0 T2 O& b        if ( FAILED(rc) ) return 3;
5 s* a, {! Q1 E5 G# G# j& N        ' t3 r( r# j$ u% ]+ I9 \" ^
        // get the root product which is the first element of root elements+ g% T, I. h. v6 x0 a; e
        CATListValCATBaseUnknown_var* pRootProducts = 3 j/ f& ^# q$ R( w1 o' N- z# p
                piDocRootsOnDoc->GiveDocRoots();
' j3 z2 Z9 j& O        CATIProduct_var spRootProduct = NULL_var;
$ ]% D- z( B% R( o8 B        $ ^# J+ B$ e& |. s
        if (pRootProducts && pRootProducts->Size())4 A4 `0 I5 [3 s/ \* B9 I
        {  
1 F; p6 P7 b: P  r- n( t5 P/ H* q                spRootProduct = (*pRootProducts)[1];# _% t' d! p* A6 e( D7 d
                delete pRootProducts;
) ]) J/ ^5 a/ K( e! m) x                pRootProducts = NULL;
7 h  q4 Z' ~1 f        }0 _5 X, y$ X+ J, v4 I
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */
1 ^9 \4 e8 p+ c) X% I8 b, g! {        piDocRootsOnDoc->Release();2 ?0 ], U  i) l2 T
        piDocRootsOnDoc = NULL;
* O0 N4 Q1 E* u6 X3 ]9 n       
$ P, G) t; A. S/ q; @4 V        // Get CATIProduct handle on the root product.% E8 D3 U/ y" z' n4 x. ^! L: O' ^% [
        CATIProduct *piProductOnRoot = NULL;
  Q$ v0 S. o; T  w- T  ~        rc = spRootProduct->QueryInterface(IID_CATIProduct,
- x* u3 A5 W% F% F; x                                               (void**) &piProductOnRoot);4 x: q9 D0 y! {8 q; I$ v
        if ( FAILED(rc) ) return 3;$ k% R& J- N8 e5 i
4 ~! G, \" m+ k9 ?8 J, b) T: Y
        /* ---------------------------------------*// @$ t0 M) ?; R+ Z
        /* 3. Retrieves children under the root   */
* O5 |# t$ |* G1 Y$ I        /* ---------------------------------------*/$ M7 {7 I' m2 |
        " b4 r% g5 v2 @, J2 @
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;' W1 Z- s; S$ R% k
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;7 o! W) ]8 c, u7 s: K
       
6 c* Q2 c0 u+ k6 `5 F- K        // then on a root product, get all the children agregated to it./ g1 S. ?2 G6 A" W: {' W
        CATListValCATBaseUnknown_var*   ListChildren =
7 O0 q0 `5 q" G- y" V6 d* [+ D! g4 A  N                piProductOnRoot->GetAllChildren();6 M! x' E! d7 q
/** @anchor err_2 piProductOnRoot not set to NULL after release */
- M. q) V) D4 U" M5 Y6 Q( v! Q: m        piProductOnRoot -> Release();
' X$ y  P8 i% K* Y2 \        piProductOnRoot = NULL;' o) G9 M7 i. R0 u* a! R
        if(NULL != ListChildren)
9 [1 m5 Y% a  p: L/ d        {5 g1 `" J/ E( Q, g9 c; Z) F6 f
                . f# W" v( N' s% \
                int numberOfChildren = ListChildren->Size();8 w* E; o& C: M! z
                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;3 s+ N( t- c) T7 g$ r

9 M, m* ]' J" h# G. v+ j                /* -----------------------------------------------------------*/( Z6 {+ d4 K# i* B* r+ p
                /*  4. For each child, get its partNumber, and InstanceName   */2 c0 M$ ?" x* t; c: w
                /* -----------------------------------------------------------*/5 L  O9 d0 ~3 o8 ^- r! z
                CATIProduct_var spChild = NULL_var;
- e7 D  P6 Q7 W! ?3 }5 V: u                for (int i=1;i<=numberOfChildren;i++)1 e+ \+ n0 A, ]9 S: o6 R' u- H
                {
/ {" }0 |4 p5 n4 \5 d" s! o                        spChild = (*ListChildren);) a" M8 e  O8 ]" K1 H  S
/** @anchor err_3 spChild not tested before use ( if !! ) */ - R5 `2 I: j! {* I! y. N
                        if ( NULL_var == spChild ) return 4;1 f( T' v0 ^; b2 {
                        CATUnicodeString partNumber = spChild -> GetPartNumber();
7 j9 A3 x# q2 }, |% w. U                        CATUnicodeString instanceName (" ");
8 r0 w) V1 G2 J& ^6 O2 n3 _                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;/ N+ G3 h2 W* {( p* o0 O' b
                        if  ( FAILED(rc) ) return 4;
3 j7 D6 ~% @1 X& q% U                        6 @% |, |% @# a( P% ?
                        cout << " child number : " << i << endl << flush;9 n/ A" D% E# B1 W, a3 Q5 d
                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;+ g$ e; H5 o; j) C5 P; j
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;! s; j7 k8 B( ?2 g9 e# `
                }0 a, t* N4 q2 a% E2 }' [
                delete ListChildren;9 n1 z2 S% v& A) T3 o; N
                ListChildren=NULL;  K9 g2 P; h& i- _3 B
        }       
; E5 e# H4 Y; Q8 y% e4 z        /* -------------------------------------------- */' G  R6 l. u: Z  b# R& y9 h
        /*   Ends the session                        */6 f1 ]3 X, S: d+ j+ ^0 y5 ~* z
        /* -------------------------------------------- */[/mw_shl_code]
; s- F4 h! \  R; m- w( V. r( W
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了