|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
! o' a! P# l1 G# Z: f2 t, S+ q
NX二次开发源码分享:查找体中最大的面积9 ?& N1 f6 I1 G# V+ @7 N
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
$ @ Q% U' p/ T7 r
: h" ]6 B& S& J$ y4 Z& I2 l4 f# p3 l5 B
- #include <NXOpen/Session.hxx>
Y. x0 w+ b m, l - #include <NXOpen/Part.hxx>2 J$ V% G9 g9 z/ U8 H
- #include <NXOpen/ParTCollection.hxx>
# v6 g; |* c& H. j& R. I4 W - #include <NXOpen/MeasureManager.hxx>
! U0 z9 O- J$ X7 W; c8 K) j - #include <NXOpen/MeasureFaces.hxx>
2 W! b( R! i' r2 I/ q8 o6 H, ~, k - #include <NXOpen/NXObject.hxx>7 x6 U( @( ], S! H& r# D; `
- #include <NXOpen/NXObjectManager.hxx>/ L+ L) f F; K2 }! _
- #include <NXOpen/Body.hxx>% H5 I9 m @: X5 Z' \6 z
- #include <NXOpen/Face.hxx>
" t( }" Y) F2 C8 ^, K& r* I" n - #include <NXOpen/Unit.hxx>7 }, ?! k( l5 K( W4 |5 {
- #include <NXOpen/UnitCollection.hxx>0 D ^+ N- r1 L6 l0 h: a
- using namespace NXOpen;
) ?9 t D, R! H" z3 s* a# i$ d
( j( V3 ?! V" `* b" t4 A0 |& x1 k- static tag_t ask_largest_face_interop(tag_t body_tag)
, Y8 m* k. f# q8 k - {: k) m& y* o' S% \ S$ B9 \+ }
- Session *theSession = Session::GetSession();9 O# x- s" T' \: K
' a+ r5 M$ B6 \0 ]- [) l& U0 @- Part *workPart(theSession->Parts()->Work()); G3 ]( w0 r( Y
$ r; W% u2 n2 Y, n% Q- w- Unit *area_units = workPart->UnitCollection()->GetBase("Area");1 @ f6 S6 Z2 g- P( H) J
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");/ ?+ s7 k. F8 R. A' V, n
/ f5 q5 j0 H. @+ z% ~4 f- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
4 d6 G. R: d+ ?- b: Z% }' A; J! S - std::vector<Face *> theFaces = theBody->GetFaces();
0 H4 \' X& i) `8 M$ {, y% e$ F
# l. B# a# U# S' N/ N' q- double bigArea = 0;7 D+ v) M/ W- n; r
- Face *bigFace;, P$ O. z7 r9 X7 ~$ P. S/ ]2 c
- std::vector<IParameterizedSurface *> theFace(1);. p, x F/ w- x5 q2 f, W ?# i1 w
- for (int ii = 0; ii < theFaces.size(); ii++)
) N2 r, d6 x" d6 E7 v& z2 c& p - {7 N, A3 h- H5 p( J$ v9 J
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);* d* C5 s5 Z( o$ {' x
! M; K( R" b3 Y4 G2 Y N7 J1 k# V1 `6 X9 [- MeasureFaces *theMeasure = workPart->MeasureManager()->
) W) F- M7 n. U1 B, u - NewFaceProperties(area_units, length_units, 0.999, theFace);
H) P1 p+ l9 j( _8 E$ A) T4 s$ F* |
" h1 a4 E0 P5 o, }4 @# B- if (theMeasure->Area() > bigArea)6 f: h- t$ F8 l
- {* G2 M! x8 F* B$ z* |! \
- bigArea = theMeasure->Area();
- f* v; Q. h+ N" S8 \ - bigFace = theFaces[ii];. I: {8 C1 T ]' t
- }% e4 Q! ~8 { o: I! V6 H
- }
6 n/ q& K) y. R( S. X$ \% d: F# S - 3 g9 A# r$ r: A% R
- return bigFace->Tag();9 [# {' l$ f3 {' G
- }
, ?0 ]8 `' W* V6 h6 o3 B
复制代码 . x% z6 M: n' t
& ?+ n( B8 j! {" S. O* B, Y' t5 m$ B6 G z8 Z, r
|
|