|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
4 O' ^3 ^" o" x% M. s
NX二次开发源码分享:查找体中最大的面积/ |$ r9 U& x4 e% m2 s
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
7 |/ v6 ~+ F7 O C5 v- Z& A! |( v& C* P* a
4 Z0 v7 e. l$ D7 Z- #include <NXOpen/Session.hxx>
. H" a0 l7 V8 ^ - #include <NXOpen/Part.hxx>
9 v6 f: T5 J" ]" P% ?6 q- L7 ] - #include <NXOpen/ParTCollection.hxx> i( h6 @0 }. Y; S* o. t
- #include <NXOpen/MeasureManager.hxx>
, S' z M( U% P4 |% G - #include <NXOpen/MeasureFaces.hxx>0 F5 {6 v0 a/ e5 |$ u8 v' W8 ~
- #include <NXOpen/NXObject.hxx>4 y; }3 r1 y# b/ A8 N( J& D; ?5 a
- #include <NXOpen/NXObjectManager.hxx>! L, B2 M2 F( w3 E& l @
- #include <NXOpen/Body.hxx>
6 H7 s% e4 U1 C7 w( ~8 R$ C. E - #include <NXOpen/Face.hxx>
3 I6 V' f% j1 e* e* n! z, m - #include <NXOpen/Unit.hxx>
0 ~" ~9 N: P3 {: B, i, D7 k - #include <NXOpen/UnitCollection.hxx>
3 N8 C6 V3 X& B0 u/ C. p - using namespace NXOpen;
) P6 J6 Q0 ]( ~1 W" H - 6 M8 ], U1 y2 S q% J9 c
- static tag_t ask_largest_face_interop(tag_t body_tag)9 y [/ s8 T: N; W2 ~9 ^( b' R
- {/ Y7 M- A! D8 y. {7 h
- Session *theSession = Session::GetSession();4 n' }7 ]0 c1 S, y
- ! n" k5 n! O" g( h; Y
- Part *workPart(theSession->Parts()->Work());
8 S4 J& d. m* s) Z' y
2 X! E3 E; Y. V' e& f5 F- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
5 o' e4 C) J' U* k* c: s2 S - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
+ J& S; v8 ]9 ?
% Z' o6 A! A1 r9 Z; R) e2 O- ?7 t- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));, c. p0 t( }3 v! H2 F
- std::vector<Face *> theFaces = theBody->GetFaces();- v4 A) t" s( u; s
- ) L& y! v- l! q
- double bigArea = 0;& [ m( x/ U% x, \6 [( z
- Face *bigFace;
" f6 B0 p% C2 p& f: t - std::vector<IParameterizedSurface *> theFace(1);. }* w6 z4 R7 u: Q: I7 `
- for (int ii = 0; ii < theFaces.size(); ii++)
2 U8 s9 J6 a! ]8 N; ? - { }9 ?; r! R$ O7 \6 i8 m" I: h5 I) H
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
9 h7 U) {' `# a8 ^) K: { - 6 n& P1 i$ ]( q9 w
- MeasureFaces *theMeasure = workPart->MeasureManager()->
4 ~) t# F1 Z! H: s) H8 S- s - NewFaceProperties(area_units, length_units, 0.999, theFace);
3 z- v" }( a1 s5 e! m/ f
+ c( g5 H* w o) }) W6 l$ s. c! F- if (theMeasure->Area() > bigArea), c( y7 ?/ _( v0 I1 f
- {
' r, |" i+ A7 [) V, ^ - bigArea = theMeasure->Area();0 V+ w) x* u* K# ] ?1 g8 a; K
- bigFace = theFaces[ii];) S' d6 V& C7 ?' Q/ t
- }* ?' [2 Y2 j. R8 H3 B5 @8 B* c6 @
- }. M! @2 W/ b; Y. J4 e
- 2 q) k/ [0 H2 O5 e) R5 Z6 j1 P( [
- return bigFace->Tag();7 i5 \- Y" e- W' s- w2 V% ]
- }
9 i$ D- c7 ]$ N* [# R: Y7 J1 `
复制代码
5 i7 J7 q' }; A' C ?9 `2 Q7 U" h- I3 z
0 R0 m0 ~" b: c0 Q
|
|