PLM之家PLMHome-国产软件践行者

Catia 二次开发源码分享: 获取所有的平面并着色

[复制链接]

2018-1-15 14:21:37 2163 0

admin 发表于 2018-1-15 14:21:37 |阅读模式

admin 楼主

2018-1-15 14:21:37

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

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

x
" ?# u- [( `4 i: f  y

- |; N7 n% ~; n* p0 N& V. S4 m个人认为,比较常见吧,如何遍历得到几何体,通过几何体获取到拓扑体,通过体获取到几何元素,通过几何元素获取到单元,单元再到几何进行判断面的种类,对于BrepAccess的获取需要借用 全局函数 CATBrepAccess !
1 ]; Z1 R4 j3 j6 D0 h
$ E9 T2 R$ k7 G# `/ q; L; l% t& I
  Z( ?0 l& I: W1 O( V  }& |, e, h7 t9 V! z
[mw_shl_code=c,true]+ t" V4 Q3 Z4 e9 v* O
        //get the main body- B( Z" J9 b/ w' l! O
       
" X8 H$ o2 W) ^+ A* e/ c; p' f        ----   -----  E* b" F) D0 |) I) g4 O. X* ~
{) S2 Z% X8 p7 R' [
        CATIPartRequest_var spPrtRequest = spPrtPart;
* w1 \% \1 O* o- D        if (NULL_var == spPrtRequest)5 A$ P9 [7 y% h3 g1 T
        {
! b5 z: T% c: @' b5 y7 ]( {                printMessage("NULL_var == spPrtRequest");( R. u) {& L7 u# O
                return;0 T( @6 Z, a; W: s# W
        }
" |' C, t. O, M, H$ W* V" {0 N        CATBaseUnknown_var spMainBody;
9 D  K1 z1 C" `& r, u7 C
' R$ P( B9 K9 O* Z/ s        rc = spPrtRequest->GetMainBody("",spMainBody);- m4 h" O" ^! w" C$ S% W
        if (FAILED(rc)). y7 y( J. u/ r, K5 G
        {  U, g9 H3 _$ A- }8 D; n
                printMessage("Failed spPrtRequest");
7 S5 G+ g  U5 w% m: G3 _                return;
# x1 ]( y: |9 k' r        }. V9 @1 K, r2 x% y$ S/ M: ^; q
9 R9 U5 H1 ^( D: T
        CATIAlias_var spAliasBody = spMainBody;
( o) ]+ ]' \- U, @: s% R. `7 w- Q: Z
        printMessage("Main Body" + spAliasBody->GetAlias());8 l2 L+ F1 P6 |% h% s. A
, [& ^6 }) q8 j( r# J& H+ Y# O0 I
        CATIBodyRequest_var spBodyRequest = spMainBody;
8 q( q- ~& ^2 O& Z        if (NULL_var == spBodyRequest)- U# g$ P6 g* @( |. N, z
        {
' _  }9 S# Y1 E5 b' c                printMessage("NULL_var == spBodyRequest");: J+ g+ A+ C. C: y5 P2 u8 e' Z0 S1 O
                return;
/ I4 `9 q2 H+ r1 G1 t1 C1 T        }2 i4 ^% n* X5 d4 T* b8 O
        CATLISTV(CATBaseUnknown_var) ListResult;
1 Z' H" g+ b, X- S- J- F        rc = spBodyRequest->GetResults("",ListResult);
7 I: L, n0 h) S2 N) [7 U& R4 _        if (FAILED(rc)|| 0 == ListResult.Size())
# {% C5 i, x6 w/ f; I        {+ |+ ^8 T0 P" W% `
                printMessage("ListResult failed spBodyRequest");+ c; {. r( ~  E" z# j! n6 [: n
                return;- e. O4 O3 m' x8 h& g8 p2 O
        }+ U8 C# I% S# ?
        CATIGeometricalElement_var spFeatureResultGeomElement = ListResult[1];
: V0 U( g+ ~4 m. T( x) Y) o. `0 c# g1 e; \" E, u2 U
        if (NULL_var == spFeatureResultGeomElement); m+ A. h4 q1 @+ F+ t0 Z- V. N- n
        {
+ @* y7 W% Y, T) N& P                printMessage("NULL_var == spFeatureResultGeomElement");3 [( m: _! v+ _2 b$ D
                return;! v0 I' g  i4 W0 I
        }  l! @  o4 N7 f6 `& h
/ Q: X$ z( B0 n3 X/ a) S7 Z
        CATBody_var spTopoBody = spFeatureResultGeomElement->GetBodyResult();
& s% B5 l/ Q7 X/ s7 Q8 U5 r$ E        if (NULL_var == spTopoBody)! w' A) X9 K' u
        {- u- ?( e3 O3 P# R" x; A
                printMessage("NULL_var == spTopoBody");( i: G4 I; @7 t/ b$ f' S- b
                return;; {+ y! Z% l1 \2 B* K
        }
% T! B7 T, f# ?# j& A( X* c& Q, Q1 \
' }6 Y9 x4 G# A3 W6 C) s6 U/ v
& N+ m* L& w: ^) J" P0 ?7 ^        CATLISTP(CATCell) cells;
! l9 b) ]/ j" s        spTopoBody->GetAllCells(cells,2); //get all the faces
" V! I5 I  n! V. e
+ b9 t6 W! \+ [        char msg[256];0 `& |' R4 m( ?4 u
        sprintf_s(msg,sizeof(msg),"Face Number :%d",cells.Size());
1 _2 X/ i# _) n% H; |        printMessage(msg);1 v/ ^$ ?# J8 O
2 `3 G9 l( k7 ^, A9 _! b, W
        for (int i = 1; i <= cells.Size();i++)
" ?3 P& \+ }5 p0 q8 Q6 G; R) A        {
. R! ?" Y6 R- I0 O                CATCell_var pCell = cells;: [/ e& V; g; ^5 @( w
                if (NULL_var!=pCell)
8 k  R8 g( t5 j                {( Q- R: o( Z( G
                        CATGeometry *pGeometry = pCell->GetGeometry();
  R, J# P* q4 S+ ^                        if (NULL!=pGeometry && pGeometry->IsATypeOf(CATPlaneType)) //plane face, H" q- r( z/ H4 A$ |3 |2 L' x3 }
                        {
, j: T) `5 q' G
9 \# P; C& K3 ^$ L+ K4 _                                //CATMathPoint CenterPoint;+ O0 o; ^, U" \) W: Z' ?
                                //pGeometry->GetBoundingBox().GetBoxCenter(CenterPoint);& _  E+ `$ _5 U5 L2 a' P- u
                                //sprintf_s(msg,sizeof(msg),"Face center :%f,%f,%f",CenterPoint.GetX(),CenterPoint.GetY(),CenterPoint.GetZ());
5 b6 D; U; F. `  U9 |                                //printMessage(msg);
# U2 k; W$ }; Y8 \                                 
& \4 v( S$ a2 H" _6 q; G                                CATIBRepAccess_var spBrepAccess = CATBRepDecode(pCell, spFeatureResultGeomElement);
( z: c* g* k5 R/ `* j7 x6 {/ ~                            if (spBrepAccess != NULL_var)
( V, v5 Z! R7 E9 n                            {
9 A& {! N- e( J$ g5 G4 z, ]                                        //assign color                               
# V% N( E5 V1 s  R) g5 n% m, b8 O: q                                        CATIVisProperties * pVisProperties = NULL;% A0 p+ ?! {  V: N5 [# G0 k
                                        rc = spBrepAccess->QueryInterface(IID_CATIVisProperties,(void **) &pVisProperties);
- w* `! B( g; ~. i                                        if (SUCCEEDED(rc)). i. J5 r/ q, f. y+ c1 `4 x
                                        {
: x0 o9 b$ O! a; F                                                CATVisPropertiesValues ivalues;
+ O2 K1 \/ m9 o( r2 t" c                                                ivalues.SetColor(0,0,255);: z5 Z' I  o1 E0 ?: B" d3 O1 i
                                                pVisProperties->SetPropertiesAtt(ivalues,CATVPColor,CATVPMesh );6 C/ o$ v, M* b$ o2 r# d: I
                                        }- F- u7 R- a* j9 Q8 Q
                                        pVisProperties->Release();
1 k- Z" O7 y# l$ n! d: t                                        pVisProperties = NULL;5 g/ g+ W6 K9 {- U% h" M
                                8 F* P' I" o& m' H8 o, g9 x
                                 }
" E- ]& \  t& J  j3 V
& N* }( J5 B8 D& j0 e                           }) ^- G' j/ U+ r9 x
                                //get alias name and persistentTag to add in the list
4 J; h% o* H4 c# z2 s3 |3 q                        3 l/ L0 j+ j" L3 e
                               
, i$ T. ]3 l5 e) u* g3 M- N; j                       
0 \/ }: n: f) v. X+ O8 q$ `: S                        }
2 t/ Y; w$ R6 E$ a) v1 O# K' h7 F/ t( L: S& o' R# k
                }
$ G. B( c. L: U6 [* N+ n' W2 Z0 V% ^
        // End of User Code6 y+ X( K0 G: E$ B# j# y; C
}
/ [! Y1 M1 F3 d& e: r. X[/mw_shl_code]3 n& g/ w$ j, F$ D
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了