|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/ k$ _* ]1 S6 L6 D0 G- m$ D: dNX二次开发源码分享:查找体中最大的面积
1 Z* d; `, Z, W6 x, r: c) o) I通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
3 q& p( {/ c+ \" Z: g6 @- s& S9 V3 h; y1 R( h2 b9 Z' Q- ~
7 b* Y: s6 [8 `2 g; O
- #include <NXOpen/Session.hxx>: {' }) q4 A4 z+ F+ z; `, p: }8 v. ?
- #include <NXOpen/Part.hxx>1 X! x* s/ T! N+ w2 K
- #include <NXOpen/ParTCollection.hxx>
: U) k/ h7 D0 j. i: K8 r# _ - #include <NXOpen/MeasureManager.hxx>- n. A' c6 \. h Z9 }' ?
- #include <NXOpen/MeasureFaces.hxx>0 } n3 v$ C- W. t( @. c" T
- #include <NXOpen/NXObject.hxx>
7 m( j, s3 b) x8 f6 Y, F - #include <NXOpen/NXObjectManager.hxx>2 S8 [, V# ], {+ H
- #include <NXOpen/Body.hxx>
# m$ d' J* A2 @3 [. r - #include <NXOpen/Face.hxx>- {0 c3 B$ M, h4 w# U
- #include <NXOpen/Unit.hxx>
- O- i3 B9 m, _" c5 O4 i/ l8 K - #include <NXOpen/UnitCollection.hxx>
# b' b" V1 j& K; y& V: S1 g7 T - using namespace NXOpen;
, L: F$ w$ _7 o3 f0 V" m* ^" [3 j
4 Z2 J3 t# l& ^6 X; b- static tag_t ask_largest_face_interop(tag_t body_tag)6 w& F7 g8 W3 g$ ?+ q" E
- {( Q' \; I8 h1 s* t8 g# i+ x& ?
- Session *theSession = Session::GetSession();" W% o( P* R& X
8 J: Q' ?3 O1 F" e- h. Y5 L- Part *workPart(theSession->Parts()->Work());
s9 B/ w' F: ]' C h' A - $ A- |. Q5 A7 `4 z7 k9 s0 U
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");1 D& D8 z+ r4 f' V# [! J
- Unit *length_units = workPart->UnitCollection()->GetBase("Length"); m: g! X8 S1 E) G
2 u, h8 ]( u, L; }' w9 G2 B1 u$ X- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
9 w: V2 p& ^% i& y+ g$ q1 D - std::vector<Face *> theFaces = theBody->GetFaces();
4 R+ P* f8 ]8 @" D. Z5 d
& K' p& d' |& X7 g% W; m5 ~- double bigArea = 0;, q- d X: N( [
- Face *bigFace;# `' j; m/ ~# K: ?
- std::vector<IParameterizedSurface *> theFace(1);
( }: t. F. D- R z Q1 v" U/ a - for (int ii = 0; ii < theFaces.size(); ii++)6 K; J( o, [0 S5 U. T0 e6 \ S
- {3 C" t3 C) W* f
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);7 @4 y3 G1 V/ z+ L9 U9 B0 ~
- - ^4 a o' _9 h: {7 e v, D
- MeasureFaces *theMeasure = workPart->MeasureManager()->7 a8 q3 {' U& f* L
- NewFaceProperties(area_units, length_units, 0.999, theFace);
$ J+ j1 J- B2 E w3 B$ N' r- v1 I( D - + k& J g! O, i
- if (theMeasure->Area() > bigArea)1 W/ ]* g! H1 E4 g- k
- {% n: s+ j) J/ f9 k4 s& G9 Z
- bigArea = theMeasure->Area();5 X: v6 v1 ~! A! F+ ~
- bigFace = theFaces[ii];
/ B2 U8 \ o( I" V0 s - }
% R( b6 n9 J) L* v - }
. v h2 q6 }) I& x3 a6 [, |
9 }# L/ ?0 W8 R# \3 n* U# R$ X- return bigFace->Tag();! k2 D4 y% { q9 R- }* O
- }
) C+ P( d) g; ~4 {" _# R
复制代码 / a/ ]6 e5 N' I* t1 Q: C) w
) T" E/ k& m3 f' @, N* l" c- \
6 s& i! c6 E) [ |
|