|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
3 Z( M3 }9 Y' U; ^5 E
NX二次开发源码分享:查找体中最大的面积
$ E$ r, W E/ a9 }. l0 H+ A通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
* Q& i p" q. v" p7 y0 L6 G" m8 \8 x7 a4 Z: B
* b% p3 h& o! y$ F) w
- #include <NXOpen/Session.hxx>
+ I5 p% z8 _- T+ B' W - #include <NXOpen/Part.hxx>
3 R5 z: u+ @ p3 m+ w - #include <NXOpen/ParTCollection.hxx>
9 r9 }1 e# j8 a% K4 x4 _/ G4 h - #include <NXOpen/MeasureManager.hxx>
# Y, H3 m& F h7 R8 s+ { - #include <NXOpen/MeasureFaces.hxx>
, L' F5 v3 r. [6 {) v: y3 @ - #include <NXOpen/NXObject.hxx>% T$ \8 U# j; V# Y9 d
- #include <NXOpen/NXObjectManager.hxx>
9 d/ T7 _# f6 D+ U, _" T# o - #include <NXOpen/Body.hxx>, t0 q- H& u" T! [ S! U% t2 A
- #include <NXOpen/Face.hxx>
p. B$ L5 a! y n$ R - #include <NXOpen/Unit.hxx>
# R2 R2 y, R7 l: H { - #include <NXOpen/UnitCollection.hxx>+ _8 ^4 ^. y3 N
- using namespace NXOpen; ^% F8 {$ _+ g* X* o* s
8 ^; e" k% ]& B% z" m) _- static tag_t ask_largest_face_interop(tag_t body_tag): L0 i: l# S( v7 O% K
- {
' _2 \( L: w5 z% {( n/ F" _ - Session *theSession = Session::GetSession();
) D/ d/ ]$ [8 k5 G0 w - k+ c7 C8 I. _" ^8 U c3 T- O" o# ]
- Part *workPart(theSession->Parts()->Work());
$ V y4 j" P7 t4 z) _ - , t9 s2 H3 G+ l$ t4 K8 T h
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
/ |4 R7 `6 L8 ^" A7 s3 s( d - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
& c. |8 f# r1 s1 G4 `3 ] h
+ A/ {; [& {3 ^( I( |- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));0 G9 }/ `& A1 X
- std::vector<Face *> theFaces = theBody->GetFaces();0 z; S% B" C9 O. f$ F% `
- 9 \, U& {1 g! t
- double bigArea = 0;: N6 h% d. D3 H4 s
- Face *bigFace;
8 H6 r' P& L0 X( r8 K' S - std::vector<IParameterizedSurface *> theFace(1);
. Q% V, V; [* X# S1 v - for (int ii = 0; ii < theFaces.size(); ii++)
; G$ n7 J; [( H1 v+ l8 o/ h; q - {/ l7 M, y! n# e W
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
3 r( {4 C% p# J; F4 c; z- V E" _ - * `7 T6 u% y% ], I$ W
- MeasureFaces *theMeasure = workPart->MeasureManager()->7 \6 C9 r& u6 [0 T. J
- NewFaceProperties(area_units, length_units, 0.999, theFace);
5 l8 h' e! x. X9 s# G0 Q
& r4 d8 l0 l O* _$ A- if (theMeasure->Area() > bigArea)& g* H3 z& v7 {; y. N) ?
- {
% Y- ~6 [' `+ D8 ?6 N/ J7 } - bigArea = theMeasure->Area();) c5 m4 D( H! z! n* j
- bigFace = theFaces[ii];
( v6 ~* u$ V3 K' n& } - }! _& \+ c; ~" s) Q" ]8 E
- }
5 o% \2 X8 j; Z& A% s( p - # G8 m; p) s5 f6 J6 `0 p
- return bigFace->Tag();
6 {% h0 G e, G% [( \) @ - }+ @7 M0 V: n. |+ W9 r$ `
复制代码 2 U P+ A- W5 k6 R9 X. b
! F# t6 d. o4 ~ K6 h/ a$ R" |2 T0 @* S: v, ?0 A# A; o/ t' ^. B
|
|