|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
$ @8 i S% M8 `# o% h; F
NX二次开发源码分享:查找体中最大的面积* c+ Y( C* s! o, j1 a6 }- {
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询8 j& v, [; W/ \3 P6 e) |/ L
: @% h9 q' s6 P
% g3 H8 W# L+ }
- #include <NXOpen/Session.hxx>+ x! b& @ S* A; e* m
- #include <NXOpen/Part.hxx>$ s1 S1 U! \( |3 V! ^
- #include <NXOpen/ParTCollection.hxx>2 R& y, y$ k) ]6 J5 W, G2 b W
- #include <NXOpen/MeasureManager.hxx>6 w$ {6 h6 p t& i8 l: s
- #include <NXOpen/MeasureFaces.hxx>
# K+ D* k, t) F: E - #include <NXOpen/NXObject.hxx>. J% h5 e+ l3 a: f: F" M
- #include <NXOpen/NXObjectManager.hxx>" p/ A" C- A, V* _7 B. J! A. ]; i
- #include <NXOpen/Body.hxx>$ q1 g6 I2 t7 [3 A( p1 N
- #include <NXOpen/Face.hxx>3 l+ x* ]$ B' s1 m
- #include <NXOpen/Unit.hxx>
' G o% z8 V' e. {+ [ [; E7 ~ - #include <NXOpen/UnitCollection.hxx>1 `, a @, o- E3 \8 Z, V
- using namespace NXOpen;' z! R7 L/ ~% [' ]4 @: _# W* ]
; @" a+ z5 C$ e4 M- static tag_t ask_largest_face_interop(tag_t body_tag)
% O8 V4 y3 }# O- m r - {
/ P: M' D% O8 @7 A/ s - Session *theSession = Session::GetSession();9 s% R. e6 Q5 w6 I! K4 d8 b
# I! z+ a/ d: d+ M5 b- Part *workPart(theSession->Parts()->Work());+ S3 {* a) [6 O+ \$ I/ s' k
8 s' T+ y! B# X, {5 E8 ~+ [- Unit *area_units = workPart->UnitCollection()->GetBase("Area");2 e2 ^/ q& Q* ]% F% O5 h( a
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
2 {( d) X0 y2 a! a
: D3 d7 Y* C+ }4 _ W* T& ]( n' x- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
$ w6 x4 P# q5 J% K- p# E I* H - std::vector<Face *> theFaces = theBody->GetFaces();1 r5 z) m6 ?, a! [9 d, W" D0 j; b
- U* I2 O( G. ~- double bigArea = 0;
7 T0 x5 v/ p( @$ L2 a$ e0 A6 S' K - Face *bigFace;
$ L C& b: T6 V! H - std::vector<IParameterizedSurface *> theFace(1);
8 Q5 y/ I9 F$ u: ?+ U - for (int ii = 0; ii < theFaces.size(); ii++)
" ~0 N: V5 P' @% B( |1 B P& u& X - {8 K3 b" |8 L# C" N
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
- F; q% f; B, D! k9 ~3 J- ?3 j& E
, j- J/ L% ]. s0 X7 q- MeasureFaces *theMeasure = workPart->MeasureManager()->
) q# j' h6 y+ k: C - NewFaceProperties(area_units, length_units, 0.999, theFace);3 O8 F. i1 M5 @6 N5 d6 Y
3 t0 j$ U+ w3 S9 ^+ u- if (theMeasure->Area() > bigArea)
' v5 n6 q$ C+ x( ? p( } - {
6 v6 [7 T& l0 }( W: \8 b/ K& ^ - bigArea = theMeasure->Area();& N0 R- q" B4 _6 w. k
- bigFace = theFaces[ii];
& m' E! Q/ I) S. x% T r - }- e& X. l8 \' K2 c5 ]8 W! F, ~
- }
% U0 N W. q+ b. J! A
D- t! u- c E( z% _) b4 A3 f- return bigFace->Tag();
$ [3 A% a; M7 Y; o* k# B' g+ r - }
1 \ P0 l8 {/ Y: b: j0 N7 ~
复制代码 # x, O8 F) C/ X8 V
" |" S4 W1 d: M$ `6 T) j7 Q7 f
! C4 j8 x. [8 k5 V: [- u, `7 I |
|