|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 s9 B" b' O& A w* h% U! p
NX二次开发源码分享:查找体中最大的面积6 y% [9 V; f# F% A! E
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
( C6 n u/ {# X3 I6 f* ]3 K7 P4 f
' U" X& {: _& k) A3 I R$ |
- #include <NXOpen/Session.hxx>
3 h b7 c$ ~: v& r( U - #include <NXOpen/Part.hxx>
: X, s s" z5 L& X - #include <NXOpen/ParTCollection.hxx>
3 j! o! M; j; ` D: ? - #include <NXOpen/MeasureManager.hxx>
1 T2 Z6 |- [6 P - #include <NXOpen/MeasureFaces.hxx>
8 I( Y' D0 O3 f4 ]% O( x - #include <NXOpen/NXObject.hxx>
) G, S8 P J/ B) ~, o# f - #include <NXOpen/NXObjectManager.hxx>1 U+ }7 \! _, v" E9 e
- #include <NXOpen/Body.hxx>
# T% s; E1 U5 X1 c: v - #include <NXOpen/Face.hxx>. r3 Y- @8 M3 ?* |0 j( Q b% D3 D
- #include <NXOpen/Unit.hxx>) v/ B" n- W% s1 f* C; T0 p
- #include <NXOpen/UnitCollection.hxx>1 k q6 _; }# L5 |( r( ]9 }
- using namespace NXOpen;6 w/ p) @" L$ k6 [
- : ], B/ o/ ?- |; C# r* f! F
- static tag_t ask_largest_face_interop(tag_t body_tag)% s; R+ {' y; k( s6 |$ c# p
- {
7 f8 r" d1 z5 o# K9 U5 \9 q - Session *theSession = Session::GetSession();/ e- x) I" S: J2 @" O
- , [: ?* \% m2 R
- Part *workPart(theSession->Parts()->Work());
) r. ?2 R Q7 K6 D - : `' \ o* |/ J- O9 Q0 e
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
Y% x( k3 f" V3 [ X - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
4 r& X6 r% }$ G) O3 _/ ?
: W$ C3 y6 N7 b+ E; O+ L- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));6 W3 E* E0 N3 |3 n2 t0 \; r$ n( b0 Z
- std::vector<Face *> theFaces = theBody->GetFaces();
" C6 }% l- a- n+ X0 S% l - 7 N' U) V* f4 q0 ?, u& A4 G
- double bigArea = 0;/ o/ J" J8 H! s' _2 D
- Face *bigFace;- E6 K' Q4 H& [# H) b- Q3 W
- std::vector<IParameterizedSurface *> theFace(1);" @) @; Z7 i8 A- i! ~6 U# e
- for (int ii = 0; ii < theFaces.size(); ii++)
- V6 {1 R( m- X, P; F - {* c* z7 _" Q& P/ t3 X
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
) P2 M0 w( y2 t! \3 b" U* r
: u' s- B: m* q- n- A/ W- MeasureFaces *theMeasure = workPart->MeasureManager()->* S& ~+ e( @( ~8 y8 q# j
- NewFaceProperties(area_units, length_units, 0.999, theFace); j) l, ^& E9 d# L
- 7 b0 N4 a o, X6 Q! i, D& e
- if (theMeasure->Area() > bigArea) o. G* [, E7 i* s
- {6 s) G- W; {' o8 U& O) m) |
- bigArea = theMeasure->Area();
; H' j0 b1 q8 j, L, z - bigFace = theFaces[ii];0 v/ o9 @' s8 |) f" \$ e
- }
& B5 J* n* M: K1 }% d - }
* q% Y# u# N: v! g ?6 Y
4 F) R8 ?( \ G' d- return bigFace->Tag();
5 u* F; f& l6 f7 Y; z% ^. ~2 ? - }
& R! s. L6 P' _2 ^: Z; d- v. D
复制代码
/ S# L7 D/ L9 Y( g; I- Q* _# ?7 `4 y3 [' h4 h# B
, e& N5 i+ A) L, d4 C: I |
|