|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
9 R* y% l) Z' o9 D3 }/ W
NX二次开发源码分享:查找体中最大的面积
" V4 g5 c7 _" |; b6 H通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询* m) ]* w% d* g8 f
" r3 s/ D- c2 ]8 Z6 V) Z: }5 b
( U ?0 P+ I* t
- #include <NXOpen/Session.hxx>1 s2 @6 ?8 [- i" L# w
- #include <NXOpen/Part.hxx>
' Q! P$ m6 i7 P) x0 p+ _/ { - #include <NXOpen/ParTCollection.hxx>
5 v; \9 Z, i& w! B0 ^" M" ~* n9 O - #include <NXOpen/MeasureManager.hxx>
! G6 ?) F' L) W1 y# c* k/ L* f w - #include <NXOpen/MeasureFaces.hxx>
* s$ L- L+ h- U4 r. _4 w - #include <NXOpen/NXObject.hxx>
1 ?* I7 o) f" j1 I - #include <NXOpen/NXObjectManager.hxx>
+ e6 T$ v# f3 A& | T - #include <NXOpen/Body.hxx>
2 b3 G9 `7 ]4 T - #include <NXOpen/Face.hxx>
/ y) W8 ^2 B9 Z5 k% O% a5 v - #include <NXOpen/Unit.hxx>
! U1 ]7 J7 f& c2 ~4 j: o' x - #include <NXOpen/UnitCollection.hxx>
, y% s* \" W2 n$ A5 x- d& M, t - using namespace NXOpen;
9 U) E O5 O" J; m# A8 l# Z4 _$ R; h
: z& d1 _0 \0 d/ X( t, F, D! M% B- static tag_t ask_largest_face_interop(tag_t body_tag)
$ |1 ~2 \% H3 I0 g" f( ] - {
: s: x3 p/ u* s. B; C/ U - Session *theSession = Session::GetSession();
5 J- b' u" v- e; m
% A* d, a1 ]- q* l O- Part *workPart(theSession->Parts()->Work());" N+ e# D5 a: J! g
- 4 q- V. `/ h1 Y
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
5 e& h# n; ^; R' e( A - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
! w+ l }" V, g s. `6 h1 ~5 b
; L. \$ n9 h6 u7 l: w; T+ p- i- y5 t! b- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
. Z, e4 }' j9 h2 k& m; U. l - std::vector<Face *> theFaces = theBody->GetFaces();3 d# h5 z9 i8 ~$ E) J/ N3 E
* ?. J) @' y# K9 p, ?3 V6 n- double bigArea = 0;+ z) N v* [; S' {0 {
- Face *bigFace;
2 Y0 | G& i6 ?0 P/ \% [ - std::vector<IParameterizedSurface *> theFace(1);/ t- {& I; ~+ R4 a7 k! L
- for (int ii = 0; ii < theFaces.size(); ii++)
' `" u( A% y6 _; B* H5 }7 N - {5 A3 M& N {0 f
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
m: m/ \8 p* t5 f3 I
2 }$ z" ^( X& V" F- Q" P- MeasureFaces *theMeasure = workPart->MeasureManager()->
6 f0 Z4 ]( f2 Q7 _& z" ` - NewFaceProperties(area_units, length_units, 0.999, theFace);
& k" ?$ @" L2 k5 f, R
( K6 _1 J9 v [- if (theMeasure->Area() > bigArea)
3 N- B! ?" q1 K - {
' X" u5 p2 Z/ [ - bigArea = theMeasure->Area();+ C: Z0 ^) l' r
- bigFace = theFaces[ii];
7 F4 g) Q3 C4 Z9 ~! P; v: z - }9 W7 e, A M: l$ ~" W- V9 B1 ~
- }' m$ C3 D! ?% k4 c
- e4 L9 B% o( x; d6 P
- return bigFace->Tag();; {4 q9 G0 F8 }$ `. |6 X
- }
$ K3 g. m% I* h) j
复制代码 . o8 B. L! s) J1 m! }
6 h, V: Q/ T- O
4 K/ x- ~0 v+ Q1 R8 h
|
|