|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
' G) k3 N/ F$ t3 R/ n6 C5 ^
NX二次开发源码分享:查找体中最大的面积
! c: ^/ n" n. [; c通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询 U; i( U2 \- T3 y
" B% \9 c* I; d
2 D4 e1 u# ^7 b. Q1 Z; s0 B
- #include <NXOpen/Session.hxx>, X. _3 _' r. O" L4 d. g2 H! T
- #include <NXOpen/Part.hxx>
& V+ |/ S6 z$ t/ b! P2 h( R - #include <NXOpen/ParTCollection.hxx>8 X% P$ k! o1 b) f2 ?
- #include <NXOpen/MeasureManager.hxx>
% Z; N; ? M" W - #include <NXOpen/MeasureFaces.hxx>
3 r3 a6 `5 s: B) J a: P! L - #include <NXOpen/NXObject.hxx>
9 s) N; K/ l0 _ - #include <NXOpen/NXObjectManager.hxx>4 B/ N; a+ n$ h+ D& Z T
- #include <NXOpen/Body.hxx>9 L# s3 t9 F. z2 p
- #include <NXOpen/Face.hxx>
! d# a3 p4 {' `! y" e - #include <NXOpen/Unit.hxx>% X) U9 D, D& p
- #include <NXOpen/UnitCollection.hxx>
) k- J5 }3 G3 N% |$ ^1 q - using namespace NXOpen;% }7 B# B' u0 W$ G9 } |
R$ _" u+ l, u- n- static tag_t ask_largest_face_interop(tag_t body_tag)/ Q/ ^4 S2 R2 k) B% h' L
- {
- F, c; q' H! z, V$ u2 G5 a$ K; k - Session *theSession = Session::GetSession();
: p E2 D5 g$ v$ }3 F& R
6 ^4 ]! @! Q& a- Part *workPart(theSession->Parts()->Work());
) D: u. Y% K: E5 w+ i4 D9 P - / L9 x- {, J, ^ G
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
4 j" q8 K Q0 V3 J - Unit *length_units = workPart->UnitCollection()->GetBase("Length");( y& p& t7 v t8 _7 K
8 t# A: J/ d) C1 X* @- u* F- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag)); A6 r% \, _9 j! Q( U. `3 {
- std::vector<Face *> theFaces = theBody->GetFaces(); I$ ?9 _& @ q, h
- 9 j c5 ^ Z* @* o$ C# W
- double bigArea = 0;
& Q5 }4 w" I6 q7 Q; ~. @' | - Face *bigFace;
* G* }3 \5 I( u0 h2 \. H( @* P - std::vector<IParameterizedSurface *> theFace(1);4 c& h y: ?# h) C' ^8 L$ ^6 t
- for (int ii = 0; ii < theFaces.size(); ii++)
: q. R4 X7 o- m0 u$ M5 B! u - {
4 n( c1 K- O0 Q' B0 T4 R8 D - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
# C$ }8 U/ A9 k6 ^: j# N2 s
, h0 P* P8 H2 k+ [0 T- MeasureFaces *theMeasure = workPart->MeasureManager()->& X5 R* K0 b" d* l: \& `
- NewFaceProperties(area_units, length_units, 0.999, theFace);
7 \8 x0 H3 U8 F2 I
5 d3 _9 Y( T1 K; {9 R0 x" `- if (theMeasure->Area() > bigArea)3 Z9 v) ^ B. m, y7 v% T; i
- {
4 n$ q s4 v" B3 d - bigArea = theMeasure->Area();& P/ r; C: x" R, |. g" H
- bigFace = theFaces[ii];/ p7 o6 O* W) q3 g0 V
- }
. G- F6 F3 V( S& X - }$ o% l+ S/ a8 D# q+ p$ C" W
# }3 k! K# ?' v! w# d3 {& \, G- return bigFace->Tag();; i. s% d+ e; j- w( L8 l
- }) e. b7 L, j r3 r
复制代码 ) V- d. `5 B' [, v: M2 f* G
. K6 P$ y. a. t" [7 O, a. m, J0 d+ a
|
|