|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
' _; \2 t; O5 S$ lNX二次开发源码分享:查找体中最大的面积2 r: m- R" n5 V4 S
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
3 N8 } G9 I( G7 q
9 \' u$ }# Z6 V/ N) ?
9 r a) {% l" u# C0 x4 i- #include <NXOpen/Session.hxx>3 w% d- d) p. T# W% t; A' {
- #include <NXOpen/Part.hxx>
1 H# V& K* _ O - #include <NXOpen/ParTCollection.hxx>( c; l1 M7 o- X/ H. {1 P
- #include <NXOpen/MeasureManager.hxx>
. s5 ~8 v4 t! G+ H- Y g - #include <NXOpen/MeasureFaces.hxx>
2 m b4 b3 ]7 ?7 \' g* ?* l# r& K - #include <NXOpen/NXObject.hxx>; P& z/ _) _0 N; h
- #include <NXOpen/NXObjectManager.hxx>
" x ]% ~& y, v - #include <NXOpen/Body.hxx>0 s- E3 n* P9 e3 @
- #include <NXOpen/Face.hxx>
$ n3 d. C! J- }# A& z' }; U6 j - #include <NXOpen/Unit.hxx> A( m" {+ ~9 T& o- r
- #include <NXOpen/UnitCollection.hxx>
. c2 k G) ~$ G2 T/ ? - using namespace NXOpen;
" m' r5 H* ~3 a. h9 d1 q0 x - . A! R' ^3 a0 _' m
- static tag_t ask_largest_face_interop(tag_t body_tag)1 {1 u0 w8 C; v6 Q) y
- {, S. i! T3 e F7 }
- Session *theSession = Session::GetSession();1 s5 Z# H) s& v4 G$ U
6 r: A5 |$ T+ W" `- Part *workPart(theSession->Parts()->Work());
. \' |/ ^+ K7 S' V% o
! j. G6 M* `) v- Unit *area_units = workPart->UnitCollection()->GetBase("Area");& C ^9 P0 e% f. h8 A
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
4 Y' c2 c% U6 I* A7 Q8 B) K6 j - , a; h) e4 B% \& r9 n
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));! _9 a4 G+ L3 t
- std::vector<Face *> theFaces = theBody->GetFaces();6 @) y0 a, t% k4 N$ u! I! R
- ; T- {8 i4 k+ S8 H- O4 C4 C+ A
- double bigArea = 0;8 \- \' ^# p# @+ K
- Face *bigFace;2 z$ F8 _5 c1 W- A0 c0 ]! D$ _3 q" \
- std::vector<IParameterizedSurface *> theFace(1);7 E: v, X0 Y0 H( Z9 t6 ^
- for (int ii = 0; ii < theFaces.size(); ii++)
1 U% e9 b$ [( E7 f& t# L - {
3 q7 ^$ j6 c! b4 ~. y! q1 M: _/ b - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
8 q" | D$ W* k
& r6 T1 b; `: e6 K- MeasureFaces *theMeasure = workPart->MeasureManager()->
6 j* S1 m, [" U9 _2 P& A5 e5 S8 F - NewFaceProperties(area_units, length_units, 0.999, theFace);) i5 m0 T, F' S) C5 U# }/ V
- : D7 d5 ?1 K* K% \
- if (theMeasure->Area() > bigArea)
6 [+ u6 a3 F; _0 C - {
+ X( [. c$ W) }5 Y( o( l# y. r - bigArea = theMeasure->Area();
. ?# v8 e7 o% a6 ~3 A - bigFace = theFaces[ii];
) d! d( Q, h( n5 E" f! v* u% V - }
" t, O$ [5 u5 e% i - }
* l9 o3 E# o4 \5 b
2 n8 w# }9 p& w+ U$ y# Z4 J- return bigFace->Tag();
7 ]! h- v$ m1 T4 ` - }* W, l3 p6 e. o# u9 D( G/ J
复制代码 2 E- E0 P& M* { ]9 a8 a7 F
% f, {% j9 T' a4 c6 c* @: ^, z2 \5 i# T5 E1 @, c# D
|
|