|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
# ` b2 ~( E8 D" cNX二次开发源码分享:查找体中最大的面积
+ N2 v$ l' ?# O) w& `; D通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询. s1 w+ T% t3 ~5 H' R& s
( s' M2 i# q. p# l ]
9 w7 a7 W# m$ I- #include <NXOpen/Session.hxx># ~$ U# ?; `7 d \+ c
- #include <NXOpen/Part.hxx>
- _) |9 d+ j9 a6 Q" l1 K' o9 C - #include <NXOpen/ParTCollection.hxx>1 z- P9 K3 R& e; {5 I; \ y: U
- #include <NXOpen/MeasureManager.hxx>
2 r# K6 T- R7 j; F, m& o0 A - #include <NXOpen/MeasureFaces.hxx>$ Z) F, K0 S; W$ y
- #include <NXOpen/NXObject.hxx>0 H! P6 x2 @$ X
- #include <NXOpen/NXObjectManager.hxx>
" y* [9 ]) N7 n" T0 H* c6 n. v - #include <NXOpen/Body.hxx>( v; o- l" ?* o- e3 b3 f
- #include <NXOpen/Face.hxx>
6 u% h( n8 ~, n6 m. N9 ^1 Z - #include <NXOpen/Unit.hxx># `; e4 n: K5 J( J9 y- z7 i8 |, c3 _
- #include <NXOpen/UnitCollection.hxx>" c6 l: e3 N6 s$ P& i: G
- using namespace NXOpen;1 h2 N* `5 w6 ~( I1 S, f+ t
' u' D& t) o, F$ {7 T! o- static tag_t ask_largest_face_interop(tag_t body_tag)
% f9 L; v* \3 h4 p3 C8 M - {" i) n! U( Z7 D3 p) H
- Session *theSession = Session::GetSession();3 Y- q$ A/ ?- p; _" ?( t4 b
3 Y! ]3 T5 e9 t/ |- Part *workPart(theSession->Parts()->Work());
; K/ l8 x4 B7 J: c$ j$ {+ E( u
3 D) y# Q1 [7 ~' R0 ^- @- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
& e) U* q& j$ ~8 s& O/ W - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
# b6 i; z- \5 g7 e D/ x# t - ) A V; _' K7 O9 q& L* J
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
" n& L* {* p3 \! ]/ e6 }" r4 H2 {- Z" Q - std::vector<Face *> theFaces = theBody->GetFaces();0 D! t/ \. K- r, `, z
- # H) e. X5 R- V! l5 q5 b7 C2 f
- double bigArea = 0;
( a7 r" R$ `1 ]4 [ - Face *bigFace;2 `: b7 [5 s5 a' o
- std::vector<IParameterizedSurface *> theFace(1);
- P. Z. E/ r, T! g - for (int ii = 0; ii < theFaces.size(); ii++)9 G* a" _* N; ~
- {
/ [6 S6 Y$ r3 H' l _! }9 ^ - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);" D( }# G3 O2 m) l, |- e
0 K# C* j+ B# q9 \2 v, b- MeasureFaces *theMeasure = workPart->MeasureManager()->
2 _) N: r$ l4 ` D* { - NewFaceProperties(area_units, length_units, 0.999, theFace);
* ?8 r3 D1 v; S1 ]( d8 H
: m4 j' Z" @2 ^" h8 Q6 r* a5 c- if (theMeasure->Area() > bigArea)
4 c6 \9 Z& I) m/ N5 S' E6 p6 \ - {
5 A1 H, [* @) L2 x8 l% ^- J+ { - bigArea = theMeasure->Area();& J6 V+ ]$ i2 ?1 J9 i4 m0 y
- bigFace = theFaces[ii];
( |) T& Y! _" r, [! a6 T4 i& q( O - }
0 R# ~* L9 y4 }- `! d. h. {& o: q1 @ - }) l0 T9 Q2 A% I( f; q: _' N! K
; f" Q6 ?+ N/ _2 d- u- return bigFace->Tag();
/ F8 q% W# C) q4 T u; V( P - }
, W8 Q# N; e/ |; g$ [8 t9 E
复制代码
% f9 a. x7 e; P6 x0 }( n8 l. ?1 \9 E' l9 M& y) T
% _+ s6 b+ Z8 K. i
|
|