|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
9 k; y! w- Y$ `! a2 h( [- `
NX二次开发源码分享:查找体中最大的面积
4 F2 R6 }9 J9 J5 z. |7 W通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
8 x/ t* d& j5 R9 E3 B4 V- k0 M
% f% u- M5 w- u/ B5 s2 H
- #include <NXOpen/Session.hxx>
1 ~2 {% M7 P0 C( ^- Y- \ - #include <NXOpen/Part.hxx>6 a# Y2 {! i, t: ^! p
- #include <NXOpen/ParTCollection.hxx>
) z# {* w# g- b" s - #include <NXOpen/MeasureManager.hxx>( L7 O, ]0 B1 c3 A0 s
- #include <NXOpen/MeasureFaces.hxx>
+ _$ D5 q7 A4 V' R* k - #include <NXOpen/NXObject.hxx>
$ |7 }7 {2 w8 \5 ~( {! p/ c - #include <NXOpen/NXObjectManager.hxx>; u3 ?/ V/ ?; x# O$ A
- #include <NXOpen/Body.hxx>. E' o% `* `5 v1 h5 [& c1 b
- #include <NXOpen/Face.hxx>
& e# j# |1 E, ^5 u - #include <NXOpen/Unit.hxx>
+ c# S6 [% A7 r7 f* Q - #include <NXOpen/UnitCollection.hxx>
# i- M0 _- j& w# w- C - using namespace NXOpen;4 F" _! |3 ~3 _, G; }
- K. U# o! P% w: J5 ]5 [% h
- static tag_t ask_largest_face_interop(tag_t body_tag)
* l7 ~6 m2 w: J9 _$ d - {8 o5 F/ ^3 x3 D. \2 t9 w
- Session *theSession = Session::GetSession();9 C% E5 |. d) j
3 Y2 L' O [1 X4 Z t- Part *workPart(theSession->Parts()->Work());
" y/ }/ J* S; G! T: e3 W - 5 _) K% Q$ N- \' m. p
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
6 o& x2 R% ]) X: H7 }0 O - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
' P6 e# P1 r& `* Q% q, e+ L - 5 t1 x" X, }. m1 G8 Y7 A
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
2 G8 p0 V3 V) i( j V7 y - std::vector<Face *> theFaces = theBody->GetFaces();% d9 Y H9 X0 ^! j
5 l8 _0 Q) S5 ?- o; Z- double bigArea = 0;" r0 V: F* a1 r/ E5 q
- Face *bigFace;4 ]: g) D P! R3 I3 ]8 @1 h( k- Z/ K
- std::vector<IParameterizedSurface *> theFace(1);
+ R. W4 B- P2 A; d$ q- |: n - for (int ii = 0; ii < theFaces.size(); ii++)
/ p4 G. F* I8 s% U- s: F - {
{; G8 |# s( o- ~$ s* t L, U8 f' J - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);; N6 K1 N# U2 o C
- " e( p$ d- c/ f9 L% A
- MeasureFaces *theMeasure = workPart->MeasureManager()->
1 W* X# F0 s9 V" S5 O - NewFaceProperties(area_units, length_units, 0.999, theFace);6 e4 ~. ]8 `4 V. e) u
1 f8 ~, o* z: H4 y0 Y+ L) Z2 `- if (theMeasure->Area() > bigArea)5 J( G$ L; T6 x3 b
- {
2 ?7 E; m, T! M y* K; g3 t. n8 b - bigArea = theMeasure->Area();
7 E* f6 y6 O0 n w, V% q - bigFace = theFaces[ii];
- X% L. J! h! Z5 }8 ~( w - }
* k0 k, |. j* m0 w# Q - }6 {/ y( ?5 k- {0 n: ~! C! S( S
% B B1 L5 `' O( @- return bigFace->Tag();( \2 g6 x2 _0 A( A
- }
- r, v! o# s0 X! o* F
复制代码 ' Y) w! V3 h, A: w4 W
- M: K# A; r: X1 i
# n- ^6 n' W% @- k, n+ [+ e5 O
|
|