|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
9 d. L3 B/ g" F: d5 F n
NX二次开发源码分享:查找体中最大的面积
6 `$ w- e( B8 ^6 d+ H通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询9 q. R7 a6 [6 `9 s# k7 l/ |
# e& M! ~, J* D( ~1 e/ I& V4 C# ^* ?( V( e
- #include <NXOpen/Session.hxx>7 R+ J0 W" P0 H9 ^
- #include <NXOpen/Part.hxx>
7 o, ?, A" q n# D - #include <NXOpen/ParTCollection.hxx>+ D7 R5 x, ]. \6 i$ v0 A
- #include <NXOpen/MeasureManager.hxx>
$ W5 M7 u: p" b( E$ h# `+ L' C - #include <NXOpen/MeasureFaces.hxx>" [2 ? A; B: }% X5 ?4 [3 D
- #include <NXOpen/NXObject.hxx>. C$ b' s% Q9 S# P& j: |1 L
- #include <NXOpen/NXObjectManager.hxx>0 W9 U% [9 C/ N4 F3 K
- #include <NXOpen/Body.hxx>- D$ R9 b" W; e. f
- #include <NXOpen/Face.hxx>0 m8 ^9 z, {- P' j! ?. m1 s0 ]: Y
- #include <NXOpen/Unit.hxx>: ?) X# m' n7 b W* i
- #include <NXOpen/UnitCollection.hxx>
. N6 u5 x; j: \! ~ - using namespace NXOpen;
" ?: [2 d P- F T! p8 |
4 |( \, l% P' R% V* j- static tag_t ask_largest_face_interop(tag_t body_tag)
, z0 X( j7 ^$ R2 e H8 V - {% d2 s' `9 q) C$ K8 _! w
- Session *theSession = Session::GetSession();; X( J3 `8 J5 x
4 L, f7 ], H! t/ j: p6 A5 g- Part *workPart(theSession->Parts()->Work());5 R, [8 i! c, [8 o8 u" f
, l+ l& e% S1 ?, |, m3 s l- Unit *area_units = workPart->UnitCollection()->GetBase("Area");5 V$ D% x0 O G, o* N
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
, W4 ]) c8 D( |; ^4 ?6 n" i
% m- S! n5 c+ f7 Y' i- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
: g( I6 u2 [# `+ |6 W4 A6 w8 | - std::vector<Face *> theFaces = theBody->GetFaces();
* h: s( n' _4 z - w5 O a6 B1 \7 j8 T
- double bigArea = 0;0 ?+ n$ `0 [* t
- Face *bigFace;- [5 o6 N# ?/ Z% T' [$ K; c% a
- std::vector<IParameterizedSurface *> theFace(1); X. h8 }+ x3 ^+ j) Z
- for (int ii = 0; ii < theFaces.size(); ii++)7 L( ?9 y3 y* f3 l8 G
- {
: Z* \7 _$ N7 Q" Y3 g1 k; a0 u - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
8 F% O( b$ }* z: X l/ V: x0 x - - B+ z' U& C# z" m1 W0 c
- MeasureFaces *theMeasure = workPart->MeasureManager()->( s" [( i# Y9 W0 o
- NewFaceProperties(area_units, length_units, 0.999, theFace);4 ^1 Q( y( C1 v9 J" j) F5 O
* a7 f2 S9 r6 G" z/ Q- if (theMeasure->Area() > bigArea)7 z) h+ M( p) k. ]! x! }; K
- {
6 K. o2 r B- e - bigArea = theMeasure->Area();6 y A2 `1 K4 v
- bigFace = theFaces[ii];
% u& t; p) \( |/ T: |* k - }
6 s& m6 l4 ^: y! ^ - }
- d9 f, e9 \: w2 @1 W& d# b
+ d, \: x! v/ Z. }) `2 T, l$ k- return bigFace->Tag();
! P& _6 |( f* X9 z) Z! X& w; b - }
: d* |9 f7 ~1 A' K
复制代码
5 |) _! r8 F8 V7 M/ o+ ~- I
1 M( ^- `5 z! z- S9 M5 H( v6 l6 Y4 ~. d
|
|