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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
/ c2 q5 U5 W6 R2 l
Catia二次开发源码分享: 获取装配所有组件列表. a: P, g7 M* H* Q5 w2 s

4 v1 G5 E/ s4 q1 G7 G, ~: Q& d1 I7 }% s- `
[mw_shl_code=c,true]/* ----------------------------*/% ]! n, t- R% o& I3 H) H
        /* 2. Retrieves Root Product   */
3 @0 k5 t" u- A) K% f5 ?        /* ----------------------------*/
7 o, t: U" B1 D, g  j, O       
3 m3 V# j# i  \  \) C3 q/ F        // Begin navigation throUGh the document => start with the RootProduct.
  h! R) x' r% n% R9 b        CATIDocRoots* piDocRootsOnDoc = NULL;; Z. @9 H, {0 ]  T6 f5 Y0 b
        rc = pDoc->QueryInterface(IID_CATIDocRoots,; _- `* z/ K2 u, u% E
                                      (void**) &piDocRootsOnDoc);* \) Z6 S* O8 J) n. J) H' O. M
        if ( FAILED(rc) ) return 3;
+ {) M1 C" }$ C        1 S4 I4 y( h0 j" c
        // get the root product which is the first element of root elements; }( F1 F  d9 h' \
        CATListValCATBaseUnknown_var* pRootProducts =
' y  j- D5 ^' \                piDocRootsOnDoc->GiveDocRoots();
; \1 }+ A# Q9 E# v9 z+ A        CATIProduct_var spRootProduct = NULL_var;: @, {% a* L* }4 T1 ^4 b
       
6 h+ F. E' B* b% v        if (pRootProducts && pRootProducts->Size())
' l+ |6 d: F/ [0 X5 z  q( c+ q' L        {  
+ c& [* O' O+ ]7 {' \# c6 r7 @6 S3 c                spRootProduct = (*pRootProducts)[1];
+ g% n1 {+ f+ k2 `4 Z8 t  g$ g                delete pRootProducts;
: k8 E, R. F2 m7 [# I                pRootProducts = NULL;# x" U) a0 C6 l6 `8 V: R/ J7 z
        }) T/ k) j  \* ~5 }0 P
/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ 4 [& d5 y8 \) ~+ Q
        piDocRootsOnDoc->Release();
7 x# ~3 V# X& O2 u2 T        piDocRootsOnDoc = NULL;/ u' o5 h3 @; Y8 ^4 B( r$ c! m
       
5 v- B6 q- m: Q( t( r2 }0 @4 L  Y2 \        // Get CATIProduct handle on the root product.1 D" [2 L( V' q2 v
        CATIProduct *piProductOnRoot = NULL;
5 W5 Z6 k; r5 z/ r) P0 T        rc = spRootProduct->QueryInterface(IID_CATIProduct,/ E- l) B3 Z: b4 r
                                               (void**) &piProductOnRoot);
0 _5 L  {4 Z0 L+ Q        if ( FAILED(rc) ) return 3;: d3 {& V8 ?2 N  }( \4 y+ B
/ m* ^, E0 c' e
        /* ---------------------------------------*/
( W. s7 O8 p* a, w  F# k' T0 U. f3 S        /* 3. Retrieves children under the root   */
! f1 W4 ^& ^4 v/ Z: R        /* ---------------------------------------*/
( U5 P8 [2 y1 @3 \          J( x6 ]" c3 q8 y
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;2 O4 k" V5 f5 ^
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;- I6 c) e! s- U- D* W" \4 p
        $ y& u8 y& _$ I. e+ d! I
        // then on a root product, get all the children agregated to it.4 n* Z$ q* f5 S/ A$ x
        CATListValCATBaseUnknown_var*   ListChildren =
* @# m$ G; q" U2 ^1 ~                piProductOnRoot->GetAllChildren();
  ~* l* @1 d9 ~, l# I- ?/** @anchor err_2 piProductOnRoot not set to NULL after release */
. U  d/ _4 O5 U        piProductOnRoot -> Release();# d* x0 ^2 G- n- A9 j( N9 g
        piProductOnRoot = NULL;1 D3 {- B% v7 y: k' z7 O  C
        if(NULL != ListChildren)
2 o3 L8 E( `1 b9 c9 K0 a        {
: j4 ]8 w4 U; k               
/ S& }* }  a0 g8 P: s8 S7 J                int numberOfChildren = ListChildren->Size();
! y( n) A* d: Y/ U4 q0 K                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;
, I/ K3 B, T' N8 I" {4 h4 a
  x4 r2 x$ ?1 T/ E) b" J                /* -----------------------------------------------------------*/2 T3 k5 U6 c  l9 N% @
                /*  4. For each child, get its partNumber, and InstanceName   */
7 t* n' i5 H8 v+ `/ `; X5 `3 n                /* -----------------------------------------------------------*/
# y, g4 X  h. Y. ?                CATIProduct_var spChild = NULL_var;
/ P( G" Z7 s) O                for (int i=1;i<=numberOfChildren;i++)# c$ ]; Y! Y1 @7 R# ^& Q/ O+ c) b1 e
                {+ e4 v% R. o5 O& ^
                        spChild = (*ListChildren);" E( g$ v2 g' d( L. Y
/** @anchor err_3 spChild not tested before use ( if !! ) */ ! y5 |4 E# @* C
                        if ( NULL_var == spChild ) return 4;
0 D. X/ U5 n. c: u: I                        CATUnicodeString partNumber = spChild -> GetPartNumber();0 L5 q% B" n5 ~. q* ^
                        CATUnicodeString instanceName (" ");3 t3 q3 ^: M" ^* H6 p! a
                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
3 C. R, p( K- y' b  x) ~9 h9 ~9 |8 ^                        if  ( FAILED(rc) ) return 4;. ]2 i' D# m. _6 p9 B  U6 X+ }
                       
  w7 n) Z% G0 ?+ f                        cout << " child number : " << i << endl << flush;
% I2 C0 r9 c3 E                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;5 a, L7 B8 X1 J: Z& N
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;- Y2 I' `* O8 M, t4 v
                }6 {6 h* Y/ q+ k0 h) l1 |1 u# e
                delete ListChildren;' A3 [1 e( X  d0 S! o3 \! Q
                ListChildren=NULL;' o: Y1 p: n' Y. ~  F9 K
        }       
9 v- W- q  f2 W& f9 g5 k, z        /* -------------------------------------------- */
% J, k# V6 ]# i9 J: k7 r+ O: p  r  l. V        /*   Ends the session                        */
1 d  i: o5 U. ~+ a# ?' E% Y        /* -------------------------------------------- */[/mw_shl_code]6 n) m) ]! T* D# Q6 x" k" f
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了