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

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

[复制链接]

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

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

admin 楼主

2018-1-10 10:12:25

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

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

x
. `4 b5 y4 n$ s, [1 i$ L) O
Catia二次开发源码分享: 获取装配所有组件列表1 B5 S" u' H+ F* ]- O

" Q; T* J' ?( ?' |% ?
0 f3 |& X* w/ h1 [& C4 Y9 L[mw_shl_code=c,true]/* ----------------------------*/
3 d; ]9 r& w& [7 ~5 J        /* 2. Retrieves Root Product   */
5 O: ]0 d% `. J5 N        /* ----------------------------*/# I  {* F: i! ?+ n0 j" F' ?, e4 ~
       
, R# x+ |7 b! S! d, t( `6 t: e1 J        // Begin navigation throUGh the document => start with the RootProduct.
) B5 i. C( }% V, F2 j+ {        CATIDocRoots* piDocRootsOnDoc = NULL;2 ~7 s+ l9 Q( Y) |, a: f1 ^8 p
        rc = pDoc->QueryInterface(IID_CATIDocRoots,9 p/ L+ ^2 o* ^* T9 l, I
                                      (void**) &piDocRootsOnDoc);
7 _; L2 g  p. V) t9 S        if ( FAILED(rc) ) return 3;
- G6 n" P% f" a5 F       
/ N" c9 k3 c% ~8 c: k+ {6 ~        // get the root product which is the first element of root elements
  ~+ a# p# G' L+ N4 s        CATListValCATBaseUnknown_var* pRootProducts = 1 @1 |: O1 n/ J8 W! u
                piDocRootsOnDoc->GiveDocRoots();
9 |! f7 E2 d; O# {* y! p% C2 e: @        CATIProduct_var spRootProduct = NULL_var;0 O  t8 ?- s; O9 \: a: t
        + V5 c3 H+ s7 Z  R. m6 z% s
        if (pRootProducts && pRootProducts->Size())$ w: [2 @4 C8 ^. J" U
        {  + L$ K7 C: J- A; {/ w# `& T
                spRootProduct = (*pRootProducts)[1];/ Y; U9 V0 X9 f# O; {9 A
                delete pRootProducts;  U7 u* w. }/ z4 `4 s
                pRootProducts = NULL;
; i$ i% N& z- x+ o5 I        }
  j# ~5 V" j; F/** @anchor err_1 piDocRootsOnDoc not set to NULL after release */ 3 x  a5 q. o  j$ O
        piDocRootsOnDoc->Release();* e7 ^5 j$ F" W8 ?' a
        piDocRootsOnDoc = NULL;: q: S- w/ O$ E. C
       
$ n. v! e8 [' b5 |4 o* q        // Get CATIProduct handle on the root product.9 o3 g1 O" R- s% Q3 X; ~1 B! H
        CATIProduct *piProductOnRoot = NULL;
1 V' C- k2 R- Z        rc = spRootProduct->QueryInterface(IID_CATIProduct,
1 N1 |& n9 a8 g                                               (void**) &piProductOnRoot);- Z* A& e+ Q* h  @1 \5 l) Y" {
        if ( FAILED(rc) ) return 3;
  x# w$ @+ u* x" @2 A3 m, n- r
) ]; Q' b5 @3 [; M4 F7 J) [+ H        /* ---------------------------------------*// q- _% i% }! }
        /* 3. Retrieves children under the root   */
9 D7 F: J/ A# D1 g* ?; A& F+ w4 }) N        /* ---------------------------------------*/
1 t8 y$ S9 i" y) O/ w7 P        ( I  P7 p: t/ L' i
        int nbOfDirecTChidren = piProductOnRoot -> GetChildrenCount() ;- Z3 R6 T8 W- T0 z/ q0 z
        cout << " Number of direct children under the root = " << nbOfDirectChidren << endl << flush;3 x% I3 e- q# R' R/ d
       
9 V' @$ E1 f* K# }  A7 |        // then on a root product, get all the children agregated to it.
$ m8 d0 e$ d. |& ?% z        CATListValCATBaseUnknown_var*   ListChildren =
! k4 \6 [* }# a0 j2 S                piProductOnRoot->GetAllChildren();& a6 m% R9 t0 h/ m! T% i/ G
/** @anchor err_2 piProductOnRoot not set to NULL after release */ ; y! W: v. A% N) E; W% b- b" c
        piProductOnRoot -> Release();9 j, Z- b1 @) E$ l7 A  j1 R
        piProductOnRoot = NULL;
; s" E6 b! l& H- G        if(NULL != ListChildren)
0 Q0 Q3 E# J. e8 T        {
4 `% }- O7 E% H5 Z; K- Y! C0 G               
, b1 Z$ T4 Y% {                int numberOfChildren = ListChildren->Size();
8 R; {7 n3 I% Y2 k7 q6 T                cout << " Number of all children under the root = " << numberOfChildren << endl << flush;1 g3 C/ f  X1 K

  @' d1 V# ^3 b) h  f, ^5 {: a                /* -----------------------------------------------------------*/! V3 @% A3 |  J: Y
                /*  4. For each child, get its partNumber, and InstanceName   */! i3 q: M: f; \6 {9 n7 F" Y& a
                /* -----------------------------------------------------------*/
* M! N& q8 V! G; E4 I6 h6 p                CATIProduct_var spChild = NULL_var;
! G0 u1 G: ?) t: ^                for (int i=1;i<=numberOfChildren;i++)
' R5 V) g( a# ]3 S& M8 r                {- }$ |% V1 m- `, a1 }
                        spChild = (*ListChildren);
. Z8 F& D& l, v* x. a% [7 P2 R, v/** @anchor err_3 spChild not tested before use ( if !! ) */
: P% c1 [$ j/ K( V" o: o9 u4 R$ R                        if ( NULL_var == spChild ) return 4;
% Y( V  x& f& r, A0 R6 E! p( y                        CATUnicodeString partNumber = spChild -> GetPartNumber();) X& d% X- s' a( Y" T& K7 H
                        CATUnicodeString instanceName (" ");
4 g$ Y) G4 `5 R2 y' B                        rc = spChild -> GetPrdInstanceName ( instanceName ) ;
+ {4 e* D+ Q/ _$ y2 z                        if  ( FAILED(rc) ) return 4;" W7 b+ g/ Z2 ~* B" Q
                        ) [9 e: W, N( ]; v7 d- ]6 c2 y
                        cout << " child number : " << i << endl << flush;
1 N- a( W) E4 V: k: i' R. g6 ]2 \                        cout << " has as part number : " << partNumber.CastToCharPtr()  << endl << flush;; n8 A% f0 R2 l, z9 |  F" Q
                        cout << " and as instanceName : " << instanceName.CastToCharPtr() << endl << endl << flush;/ W, V7 o' g$ S- I+ r! E2 Q
                }. G- t' M: ^3 {# f! }/ ]
                delete ListChildren;
$ {- V5 f  S! m' M5 _3 n                ListChildren=NULL;
' r4 y: z# @& p6 h  A        }        8 ^& a/ h3 r4 Q# }
        /* -------------------------------------------- */
9 N% k) Y+ x% j, ?3 i" B# L        /*   Ends the session                        */
$ R' L5 Y2 b! Y: B! F+ o/ }        /* -------------------------------------------- */[/mw_shl_code]6 I- h/ {9 r3 w/ W, h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了