|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
( c! U9 C, B4 N5 K: w7 B
NX二次开发源码分享:查找体中最大的面积
; Q7 f/ g: J( j4 o通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询. K' t. T: o9 h! T, v" p- b& z
, ^/ W) U: m( P4 }8 g( P8 c
* j! _4 Z! U. J$ u$ ~
- #include <NXOpen/Session.hxx>
& w% I m% g+ Y# W: y$ `9 e - #include <NXOpen/Part.hxx>
8 m+ D3 ~7 ~. W4 g - #include <NXOpen/ParTCollection.hxx>6 t- x. F+ A7 E U7 V2 j. S
- #include <NXOpen/MeasureManager.hxx>) ^: N0 W( g% i- `* }9 b
- #include <NXOpen/MeasureFaces.hxx>- b0 x/ Y% P9 ]# V$ y9 _) f
- #include <NXOpen/NXObject.hxx>
0 `; ?. I/ F! t; O, { - #include <NXOpen/NXObjectManager.hxx>
3 \ L5 B2 s+ @1 b O2 V - #include <NXOpen/Body.hxx>
# D$ v- O. s: s# p; Q, g! M - #include <NXOpen/Face.hxx>3 {0 J7 L8 L5 j
- #include <NXOpen/Unit.hxx>
. D5 h" h& C3 P t) z. e, G - #include <NXOpen/UnitCollection.hxx>
, |2 w6 r& T, H/ v' w3 j - using namespace NXOpen;& [/ Y/ E! V+ x% |0 E% _* w# [, ?! u: r
- e: d* m3 m5 g1 P
- static tag_t ask_largest_face_interop(tag_t body_tag)
* P# q. I' b2 C0 @. { - {5 A" i% Z6 J) ]+ E. Y6 Z( [7 O
- Session *theSession = Session::GetSession(); R9 T8 }- G9 x# X
! E( {* J# ~, F- f d; `- Part *workPart(theSession->Parts()->Work());& H( X& b5 s: O* B
; h8 i& D1 \8 \5 d- Unit *area_units = workPart->UnitCollection()->GetBase("Area");9 ^+ ]9 l5 s* [5 ~7 l
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");% R% j& d1 ]" H
- ; |" B* L. ^7 r$ U2 e l' x
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));5 `5 Q2 ]/ @. q! L. y( d
- std::vector<Face *> theFaces = theBody->GetFaces();- \7 y# [" A k. [7 v' j
- 2 `& l3 p& G6 u i9 p2 o! F. ]
- double bigArea = 0;
; k# M/ U% v$ P - Face *bigFace;
; N* T! J. Z2 q, ^/ I! v* d - std::vector<IParameterizedSurface *> theFace(1);( {5 s! g$ k4 [) u7 z! W
- for (int ii = 0; ii < theFaces.size(); ii++)
: h, K0 P+ m0 P0 I& k! O& z - {
/ L. W- O) M( q0 g7 ?2 U - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);/ Q1 H2 g# H$ t& v8 m" ]0 `
( A8 b) A! e# E' b) m- MeasureFaces *theMeasure = workPart->MeasureManager()->
3 L/ Q/ X" x2 G% _, G& D D1 y. G$ \ - NewFaceProperties(area_units, length_units, 0.999, theFace);
0 c2 m6 H0 X6 t8 j/ x6 y( B; H- M s
/ B% J8 k5 H8 j% B- if (theMeasure->Area() > bigArea)3 P% w7 ]% t) S7 p! W/ b, s
- {8 |' D! z5 V. F3 n# Y/ x
- bigArea = theMeasure->Area();! n# w. g! r: _) P3 K
- bigFace = theFaces[ii];: }8 ?! Z/ |2 [+ P+ }- i8 ]
- }$ D; k8 X4 M( x9 O+ ^ Z
- }6 y$ z* c. `3 T) u8 S$ G* g5 V/ H
$ U9 f& U( J" X% ~ N% U- return bigFace->Tag();
3 q4 K1 i) q$ }% I: P - }
, m% @6 e1 T: e& F5 P0 c
复制代码 . i2 d" m% H+ J. K5 M& a) E8 r( j
* _4 e4 ?4 i0 h8 N/ H: t: V( c
, R. I R4 c3 S7 F; p- A4 V+ T$ I |
|