|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" j% c- N* x0 l. q9 c1 H; hNX二次开发源码分享:查找体中最大的面积
0 Y7 I1 ?, q3 U通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
# R3 D) S, X& ?% |' B2 _& t$ ~: |; y" n8 `8 C) s3 A7 W# y& T
# r) {8 h( U; u
- #include <NXOpen/Session.hxx>6 R$ U. @4 w' w3 G: W
- #include <NXOpen/Part.hxx># t& w. y4 x' O
- #include <NXOpen/ParTCollection.hxx>/ a4 v, W: y I4 G
- #include <NXOpen/MeasureManager.hxx>
. R/ h4 A3 J/ l% K$ d - #include <NXOpen/MeasureFaces.hxx>
" ] M, r) q& D- f# [4 a - #include <NXOpen/NXObject.hxx>7 j- i! ?/ d3 w! i( ^1 W# p
- #include <NXOpen/NXObjectManager.hxx>, m0 g0 S- _ n
- #include <NXOpen/Body.hxx>
( M# d8 E% _% m! b$ V, D - #include <NXOpen/Face.hxx>* i$ R. z$ x& X( D6 Q" J1 [
- #include <NXOpen/Unit.hxx>' \0 l+ \+ z) Y: ]( z
- #include <NXOpen/UnitCollection.hxx>/ _0 O3 I! k8 f/ T0 K% i
- using namespace NXOpen;
9 H/ Z$ X; o. g
5 f- }" A' x( {& g9 R- static tag_t ask_largest_face_interop(tag_t body_tag)# v- ^8 L7 x, H2 P# S; R
- {! q5 n3 }0 ~. z9 Z% N* k$ i5 G2 D
- Session *theSession = Session::GetSession();
# ]. o; B# Y+ V4 R. j* x9 I# V- O$ z - " x' y2 s9 I% L9 j. e' R
- Part *workPart(theSession->Parts()->Work());
7 r" {, n6 G4 y( {, m$ t# F% M - - M" I2 R6 ~5 b
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
& i' x1 C+ y& c$ j4 { - Unit *length_units = workPart->UnitCollection()->GetBase("Length");# A( _( p& j( {+ H9 m: y4 N
! Y/ y/ C* e# q: j+ R- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));9 R f6 x7 m# X8 ?6 \7 n4 T0 M
- std::vector<Face *> theFaces = theBody->GetFaces();
$ l; T+ d i) y" q- l& S/ Q - ( I, ` o9 q5 Q! F' Y0 \! @
- double bigArea = 0;: f9 L: @# n' ^+ `" t8 d# r
- Face *bigFace;+ B/ P" H7 \0 l) [% ^2 X o
- std::vector<IParameterizedSurface *> theFace(1);2 p* G. h* z1 L6 Y
- for (int ii = 0; ii < theFaces.size(); ii++)/ z, C; U5 r$ q* Y
- {
. ^& j6 _9 C' h- | - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
]+ t, J' X( _9 r2 k
5 u/ P' f& E `1 e v- c- MeasureFaces *theMeasure = workPart->MeasureManager()->
t! p8 d. j. H% S% W' |" T' e - NewFaceProperties(area_units, length_units, 0.999, theFace);
$ F$ z S; W ^8 z% r7 e* `( y - w- t, l' \* n$ w! D$ O3 O5 m2 h% H, ^
- if (theMeasure->Area() > bigArea)
' y; A/ k$ ^8 v h5 j; D- S; \ - {
2 y9 J& N, w9 \6 z; Q7 T! p - bigArea = theMeasure->Area();
$ y1 Y1 O: D0 F. h" R# s( v ? - bigFace = theFaces[ii];8 V9 t8 F _% M+ Q) Q( G! m
- }
+ y. ~3 g; y0 G - }( D% B. t5 T+ I! I9 c
- - k- E5 y0 J6 E: S/ `4 p* U
- return bigFace->Tag();
( n+ W1 d* g7 T- C% Z - }5 P. `( ?( O# ?7 _0 F ^+ k
复制代码
, ]' \" E, G/ a8 h* r9 \0 K& U$ ~7 Q, f% Q% ^3 k5 C' l
) A a7 d8 ]; G$ X
|
|