|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
\. `# z3 G0 X" K6 _NX二次开发源码分享:查找体中最大的面积
$ c2 v) T5 X/ f6 Q& T: b通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询" J% t$ Y0 i' M6 C; W: d' y* x* W5 s
8 T1 }% w$ `2 f
E6 V5 b, p. L7 R$ Y
- #include <NXOpen/Session.hxx>0 a1 V' ?$ j- _1 L
- #include <NXOpen/Part.hxx>( r: l7 j/ H8 @
- #include <NXOpen/ParTCollection.hxx>; j& y4 e+ v- \/ U. J, ]( k
- #include <NXOpen/MeasureManager.hxx>5 T8 X4 i1 t" n% F2 i
- #include <NXOpen/MeasureFaces.hxx>! B7 O6 F: @, J, C9 I
- #include <NXOpen/NXObject.hxx>5 l2 `) U1 D3 r3 x( A) a
- #include <NXOpen/NXObjectManager.hxx># Z$ K \) B1 L3 k/ r
- #include <NXOpen/Body.hxx>
. ]1 @7 m$ h( ?8 T- X7 [* h - #include <NXOpen/Face.hxx>7 D' o7 T% |/ p4 [, K* ^3 T% j
- #include <NXOpen/Unit.hxx>/ ~* _9 X, f$ }( ^6 ~- W9 O+ X
- #include <NXOpen/UnitCollection.hxx>; B' K8 K2 N% x
- using namespace NXOpen;
7 I1 t( l! r. w4 H, ?/ m- M. Y - 3 ^" v8 W+ o" `+ S# `" w
- static tag_t ask_largest_face_interop(tag_t body_tag)
( O/ r5 P$ {$ v( }: P2 k7 a0 n - {
/ L5 K5 G5 N+ ?8 D& L7 ?4 x, Y0 ?3 X - Session *theSession = Session::GetSession();
6 g% ~6 L z( s( L! I1 p
( U% m0 s6 J# V% ^" \- Part *workPart(theSession->Parts()->Work());
' V7 D$ Y; ]3 F' f ] - 0 H7 R4 B# F& }. R
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");) Y2 L" ^4 r# F6 z2 \6 S
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");/ O" M. _3 n- a
- " Q" |( Q5 W& ^+ Z
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
! u" d% A6 ?0 C* K$ G& P, _0 S5 p3 u - std::vector<Face *> theFaces = theBody->GetFaces();
* H9 T& h* C, z# Y( j
3 j, R7 `! X, n2 |1 Q- o- double bigArea = 0;: l/ v& z! w$ e5 Y' R1 _) i
- Face *bigFace;
2 @! C4 }5 b- p9 Q, @ - std::vector<IParameterizedSurface *> theFace(1);+ h: W3 D, D' _$ z, F( s+ w' L
- for (int ii = 0; ii < theFaces.size(); ii++)
U4 T" ~1 V9 v( q - {+ ~! C7 ~6 C0 b2 P
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);* i9 T. f; [5 c/ n
& P0 _+ R, }/ F1 i; m0 q- MeasureFaces *theMeasure = workPart->MeasureManager()->
0 G( s. {3 m9 ?* V - NewFaceProperties(area_units, length_units, 0.999, theFace);
W2 b! A5 v( w0 M& u9 J - 9 i# N9 q+ m+ K6 C5 L/ _
- if (theMeasure->Area() > bigArea)
' U! J* Z6 N- c3 ^9 F! C - {
& s+ t }- }+ V! Q$ d - bigArea = theMeasure->Area();2 G; X: Y) f6 i7 W* V
- bigFace = theFaces[ii];$ b6 U7 a" v* W" C9 v
- }9 a2 s4 B$ Q: O7 p
- }
$ L( v7 C0 s, ^$ n8 s - 0 y( l- M- {! U+ D" s4 [. i
- return bigFace->Tag();4 `/ J& ~" I$ [9 Z
- }
4 E% X( H( c7 d4 H: D) h- R2 X3 d
复制代码 2 Y/ y/ d# Q- H! X* b' z9 q0 s
* |( L/ B+ j0 H9 V6 [2 H# c6 O5 n0 ^( [! m* b
|
|