|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
. w: U6 N, q* }7 @2 x. E
NX二次开发源码分享:查找体中最大的面积
# i0 t* s- S4 B; n5 e: E通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询& a/ L( X) c) n$ c ~6 i' ?
. e3 y( T, v% e: {6 i. H- u9 B0 ~# B9 \( V( P9 `3 G
- #include <NXOpen/Session.hxx>( R! J8 Z: n+ e) N {+ u5 ^3 {7 b0 O
- #include <NXOpen/Part.hxx>
; v$ r$ k( k# d& C* w/ ` - #include <NXOpen/ParTCollection.hxx>
( O2 |4 e' U1 A* v7 _3 ~ - #include <NXOpen/MeasureManager.hxx>2 g) F: W# n4 T( {; O7 E9 `7 R& u
- #include <NXOpen/MeasureFaces.hxx>/ Q! E% e$ Z( {- s5 I) A
- #include <NXOpen/NXObject.hxx>
( _$ \8 R2 A# c, O; f3 C3 K/ V4 W+ n - #include <NXOpen/NXObjectManager.hxx>
! B5 A6 v/ Y% D& Z: Z - #include <NXOpen/Body.hxx>) h. a1 W0 D' V; k; M/ ?/ j/ @
- #include <NXOpen/Face.hxx>7 ~7 k$ D! f; j6 x
- #include <NXOpen/Unit.hxx>
: P3 P% ?. E% L% T# X9 c: g - #include <NXOpen/UnitCollection.hxx>" {7 M, O- \0 |& T& T( L+ r/ R& q3 g
- using namespace NXOpen;
1 V$ P) T1 E# j4 }8 O - + K$ M `, t D9 {
- static tag_t ask_largest_face_interop(tag_t body_tag)9 Q5 P; c( ~/ n' r* G
- {
- b3 }! Q3 \5 e6 Z: I; R6 z: q/ ? - Session *theSession = Session::GetSession();
" Q% I0 K5 |5 c( {0 g
) C2 J* x7 o, p; t# S! D( X; e( c. r: N( O0 u- Part *workPart(theSession->Parts()->Work());
P. w& G: A, c2 ~& z* L( s
) M$ S% F5 t/ w" `% O5 y5 \+ [- Unit *area_units = workPart->UnitCollection()->GetBase("Area");8 S! \! O8 v: k0 `: L. N# S
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
3 [. m: m' N: x' Z0 C2 }8 W x
. @% G+ q0 l7 {& E4 w/ w- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));" R: R2 e/ r( h, Z% b+ P
- std::vector<Face *> theFaces = theBody->GetFaces();
' q/ m0 z! e5 u
- }! q' p9 `7 s' }- double bigArea = 0;
+ \1 N5 l K* w: @7 ] - Face *bigFace;. s$ J# w3 Y% u
- std::vector<IParameterizedSurface *> theFace(1);5 k+ [6 `6 u, L& b$ a8 b5 }+ v1 t% ^
- for (int ii = 0; ii < theFaces.size(); ii++)+ A' s z+ Z2 h% D8 _( o+ m% q; k
- {; B5 | B( T! x+ \
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);& k* y; d- k- M5 H, ]* P
0 r4 B( D6 D/ s1 X- MeasureFaces *theMeasure = workPart->MeasureManager()->
* h2 M L& Z4 X& T - NewFaceProperties(area_units, length_units, 0.999, theFace);
5 i# N) ^3 l$ Q# l; w. v0 p
3 Q s# o4 O9 n1 c% Z3 l( Y- if (theMeasure->Area() > bigArea)3 G6 m/ s) S w/ H8 A
- {9 Y+ E* i7 R+ w. z
- bigArea = theMeasure->Area();$ U* s. r, b1 Z% B) t' [
- bigFace = theFaces[ii];
+ i% U$ r4 O* ]- a' M& \. O4 _ - }
# c6 A6 g- N9 v- ], q2 O) M1 {1 a* p4 ^ - }. f& A* s) z6 x, A9 _
, M @$ T- a& D' y- H8 R- return bigFace->Tag();) o' l& b j0 ^: A
- }
- t8 Z) ^- e* U- v
复制代码
2 E; p& L7 d, Y: s# ]+ \+ R/ ~) i5 C3 t% h7 p6 R
4 N/ |7 S7 y, X% M" A |
|