|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
7 x! y- N3 L7 J2 B- k% s3 Y" I
NX二次开发源码分享:查找体中最大的面积
d' H9 d& _% q# d: N( F# i通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询: W5 l" A: t/ k6 Y" v: e9 ?
' H4 X4 ^- ^- _2 R1 h* _% Y
- Y" s' z" Y8 W' _: w! Z w- #include <NXOpen/Session.hxx>
) ]5 B* \- {' _0 z& V3 D' U& o - #include <NXOpen/Part.hxx>& u! L, X! c$ R. z* K
- #include <NXOpen/ParTCollection.hxx>
) v# r+ L G6 D# C2 u% k - #include <NXOpen/MeasureManager.hxx>2 Y K! s: l/ ?1 ]! ~
- #include <NXOpen/MeasureFaces.hxx>' I4 O2 z9 S* p0 C% x/ p9 |+ Q
- #include <NXOpen/NXObject.hxx>
- e" R3 _+ l5 ^2 H% z2 ^3 o; R3 v - #include <NXOpen/NXObjectManager.hxx> [3 L/ ]% [4 v# `( |* C+ A
- #include <NXOpen/Body.hxx>0 T8 Q0 z" I/ e
- #include <NXOpen/Face.hxx>
5 X4 R8 Z1 p3 x( |; n - #include <NXOpen/Unit.hxx>2 k5 W7 i4 u8 `6 `3 W' B
- #include <NXOpen/UnitCollection.hxx> @8 t$ k: F6 x# k3 B
- using namespace NXOpen;2 C. |+ G( z1 i; Z& p( Q
; V) B! D+ f7 w I/ f- static tag_t ask_largest_face_interop(tag_t body_tag)
6 p+ h- X7 `# r - {9 b w0 [+ E/ y4 ~' M
- Session *theSession = Session::GetSession();/ O6 A" ^$ D! z
- $ ^9 w/ S# v8 p2 \& D, o& g
- Part *workPart(theSession->Parts()->Work());
7 y2 X' r' q8 ]' n' ^ - - q9 `* i3 a' D( v( j' T9 U
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
! }4 d% P6 E4 H, S - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
u9 o& s7 P3 e' t# M6 w% W5 l. P y - 9 Y. R% ]: Z2 _+ m9 a; O, l
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));. y: j/ r) { q8 K7 ^3 e* m! N
- std::vector<Face *> theFaces = theBody->GetFaces();
0 E# \$ h2 f$ v
7 V/ }5 F4 F8 S6 B8 S$ e- double bigArea = 0;
( D0 Y J; A6 s M - Face *bigFace;
! Y, V( Y( Q% C# d" C( I5 x( j - std::vector<IParameterizedSurface *> theFace(1);
, s/ v4 v: A' Q9 t6 H8 x" p3 I - for (int ii = 0; ii < theFaces.size(); ii++)
0 t' R6 B- U. r7 P* D$ Q" s9 g - {
; s4 N6 K9 T2 l9 M* ? - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);& u( Z1 W. c4 R# q
4 {/ @ k' C4 M- i/ ]8 E. ^- MeasureFaces *theMeasure = workPart->MeasureManager()->! r) Y6 b$ R/ r7 G
- NewFaceProperties(area_units, length_units, 0.999, theFace);( W, @& \6 ^/ _# {& I/ D' Y3 v
- + _- `$ F" q) ~* r. m1 [
- if (theMeasure->Area() > bigArea)
- [( W5 N7 l( }8 Q$ L$ H" Y - {
! _0 h2 L1 j$ `7 |1 V9 v - bigArea = theMeasure->Area();+ q& c1 ^( G8 m
- bigFace = theFaces[ii];. e: u4 L7 G V5 d+ p; t7 Y
- }
! z+ ]3 l7 c2 E8 E5 `, S1 h - }
% ~% [6 @; W) ], {1 k/ M, s; v
" g+ |; M' {1 }: z( n- return bigFace->Tag();
8 {% Z) r+ `9 t - }
! J- S! y* j4 e1 h
复制代码 + k3 \1 [9 L9 e2 C4 a
, W7 g" D: ~) N$ ~& M" D8 m+ T! `7 R7 }1 \( `; D& B# I
|
|