|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
! T1 |& {6 k+ c0 V% GNX二次开发源码分享:查找体中最大的面积
& O5 L- F O: m* T4 k/ h7 E9 P+ l通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询* L& V- O, s! e% G5 |8 |/ C! |
1 ^2 b' {$ j5 L. Q. k: A1 ?0 d4 y+ r7 W7 d; P' P9 F2 v! F' Z
- #include <NXOpen/Session.hxx>
* c) k& @4 O0 w1 k: s - #include <NXOpen/Part.hxx>, Z8 e* e0 s9 i! M( N( j! p+ g
- #include <NXOpen/ParTCollection.hxx>; e. \' a+ d, d9 C
- #include <NXOpen/MeasureManager.hxx>
4 W8 G: m* U9 w8 \$ t - #include <NXOpen/MeasureFaces.hxx>3 m* H+ C, E" b! n8 @
- #include <NXOpen/NXObject.hxx>6 V1 k* d! L% X6 {2 `& }
- #include <NXOpen/NXObjectManager.hxx>; \1 X6 ?' V4 ?. @/ L
- #include <NXOpen/Body.hxx>% k7 _! C9 x3 @
- #include <NXOpen/Face.hxx>8 e2 H- O) e4 y4 ^1 I- n
- #include <NXOpen/Unit.hxx>
% k5 J5 ]+ o* {6 a2 _( m+ A - #include <NXOpen/UnitCollection.hxx>
2 @: {# Y& |3 Z: U7 A# Z* T) y - using namespace NXOpen;
, a: Q# ?8 y4 c5 h
" d# r$ m8 s# ~0 G* n" y- static tag_t ask_largest_face_interop(tag_t body_tag)' _7 j E2 y2 U# D
- {9 l/ v$ o% }7 N; X3 R
- Session *theSession = Session::GetSession();3 Q L$ Y* Q2 l( s6 m j
- - m+ q( z/ G$ t9 [
- Part *workPart(theSession->Parts()->Work());% W ^) M0 P* j9 X- _( l
* Y( L, @) y- ]0 ?- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
" Y; i2 o7 j8 A0 I0 r( E - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
3 @3 B. S) Z7 p
f% O/ G( b" U2 [" C; z* F' d0 ?- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));* |3 h9 D; V/ M- K) b' A0 h
- std::vector<Face *> theFaces = theBody->GetFaces();
1 O5 ~1 R1 S$ ~5 T
. b Y; }9 n$ b- double bigArea = 0;
7 M8 J8 h$ P! ~* x. E - Face *bigFace;
" ?. _' ?0 z* \) x5 w - std::vector<IParameterizedSurface *> theFace(1);! p, }. T8 a/ ~& F& d
- for (int ii = 0; ii < theFaces.size(); ii++)( o' u) h I J* i5 [* x
- {1 r. \: }: ]$ j
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
5 F2 x" _% P9 B2 N3 w3 f2 N" ]
, s, ]0 t8 l ?/ ?# G* q- MeasureFaces *theMeasure = workPart->MeasureManager()->
) J+ ^2 u9 @" s* r) B - NewFaceProperties(area_units, length_units, 0.999, theFace);
: z; R" p [5 r% g - 3 R' G, x) t8 n, ~" e
- if (theMeasure->Area() > bigArea)* P% U% p& N. @' V1 X
- {& @+ y4 R9 v' O2 }
- bigArea = theMeasure->Area();" J, ]2 E1 ]' J9 O3 q* P! F
- bigFace = theFaces[ii];
7 _' G. @0 d! Q4 M4 n4 F - }
' r, h& s. F* W# c, x, ~ - }1 S2 X1 I+ f4 M$ W* Z# O
9 c4 r6 m2 ^# o( ^, L8 c- return bigFace->Tag();: y, d, a$ |3 j
- }+ z: r7 c; ~7 O' u' ]
复制代码 . n j3 q: A0 G
0 v; z, P" r9 W, f
9 S9 v1 m& w, z$ y+ C! i |
|