|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; b+ m- O4 [# H
NX二次开发源码分享:查找体中最大的面积
4 B; E/ t _& D4 C8 B- j通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询# [- K, q1 R! F# I9 g
( F! a4 E: i1 m( B& w4 x( f3 p
* Y5 z0 M- B) ^, V6 [
- #include <NXOpen/Session.hxx>
, J v& `" I* v# I# D% O$ V - #include <NXOpen/Part.hxx>: M3 {) y" ?; B4 J3 ^
- #include <NXOpen/ParTCollection.hxx>
! c3 |5 u1 U: s/ t( H- p- y - #include <NXOpen/MeasureManager.hxx>2 }7 A5 Z$ ]4 }' H8 B
- #include <NXOpen/MeasureFaces.hxx>
7 ^6 Z, a" p$ N- c9 u# L - #include <NXOpen/NXObject.hxx>
) j* ?8 g7 l% z( ~' g* N y) R - #include <NXOpen/NXObjectManager.hxx>
7 C4 _6 O1 t$ Q9 N - #include <NXOpen/Body.hxx>3 e% K9 v j- z
- #include <NXOpen/Face.hxx>
! H s O y& g* L1 { Z& R - #include <NXOpen/Unit.hxx>
e+ h0 e4 l- g - #include <NXOpen/UnitCollection.hxx>9 l% S6 r0 L l9 h# b
- using namespace NXOpen;
/ p* }3 p) A) s
# P* k' m4 y- r8 K% ?0 {7 t1 Y/ ~; D- static tag_t ask_largest_face_interop(tag_t body_tag)
) C+ r- {3 Z) r7 Q4 F- r - {
# t6 u5 g0 _! m" k - Session *theSession = Session::GetSession();
) y. W$ P9 A3 g4 t8 p6 k - 3 w: V5 W* v1 Z- {
- Part *workPart(theSession->Parts()->Work());
3 ?6 I9 [# Z# h1 E$ ~9 V1 k
0 \# W8 n: V1 d6 v0 f- Unit *area_units = workPart->UnitCollection()->GetBase("Area");% k8 ]) p6 A" ? d/ N- [ c/ q
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");! F7 x, b6 T/ f' G0 Z
+ U! e+ p9 T: O. ?+ r- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
( J3 u" O4 Y! P - std::vector<Face *> theFaces = theBody->GetFaces();3 n( M; F% _. T- Z1 p0 f
; R* `( A' I- {' v- double bigArea = 0;" I8 |; M& e# N( D+ I
- Face *bigFace;
5 f+ n1 k9 S# P( n- ]. x+ { - std::vector<IParameterizedSurface *> theFace(1);
: p$ K R0 R+ h" q - for (int ii = 0; ii < theFaces.size(); ii++)( ~. n G1 a8 t+ }
- {
. s' e0 p& u. j" D4 r j - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
' h8 X& y `6 u4 z. {" T
& H6 m, U0 ~0 U# `/ P0 I8 P- MeasureFaces *theMeasure = workPart->MeasureManager()->
( _, A$ j6 k. g' e! d. O, d - NewFaceProperties(area_units, length_units, 0.999, theFace);8 [& P% |& ~$ ?& ~7 V
. {* }; y0 e) a2 n3 q. \2 O1 _) Z7 C- if (theMeasure->Area() > bigArea)1 e: w0 ?# v! e m
- {
" Q; y9 d5 w1 v7 D0 w - bigArea = theMeasure->Area();) D. f1 N9 Y3 x5 @* x
- bigFace = theFaces[ii];* ^) M e3 k2 U. G8 L, y# O
- }0 t+ n! W+ a7 w' _; A: B3 \
- }& f* Z1 r/ {: W- D+ i
: y- L! m$ n/ V. S6 x- return bigFace->Tag();
+ c) v" ^/ g7 o. a - }% L2 ]( M" i) C! P) G, ?4 H
复制代码 5 M! Q( v/ e# S/ g
. E6 X0 U2 c& b! [3 Z: ]9 ~0 H
8 t) X1 T( \! L; L, } |
|