|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" y- j; T s$ q7 i6 n( x N
NX二次开发源码分享:查找体中最大的面积
3 d; z6 J6 `% B- S4 j7 z- Z通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询5 d3 h: ~6 z: }+ D
4 {) `; k6 U* m. ~/ ^* o
' {; [3 V$ J9 c/ |) A# Z( Z
- #include <NXOpen/Session.hxx>
) q) i3 a6 o8 l1 c* ] - #include <NXOpen/Part.hxx>6 U% x4 d" [* q/ o G( q" g
- #include <NXOpen/ParTCollection.hxx>4 f! W6 L# ^8 s0 N( H, g
- #include <NXOpen/MeasureManager.hxx>1 N( z9 K3 \+ O" e) q! e0 @$ V, Z
- #include <NXOpen/MeasureFaces.hxx>: ~- ]( \$ e# Y, S9 k
- #include <NXOpen/NXObject.hxx>, t2 L7 J4 q% \4 P3 W3 Q
- #include <NXOpen/NXObjectManager.hxx>
5 ~: R, Z0 n. Z$ V+ K" v - #include <NXOpen/Body.hxx>
: B# R0 ]' ~* R8 V - #include <NXOpen/Face.hxx>
; _% _/ g9 i% S. X# W" M - #include <NXOpen/Unit.hxx>
5 c3 F/ b$ ^* n2 e9 d - #include <NXOpen/UnitCollection.hxx>
* b' U' V! a3 B3 b% O - using namespace NXOpen;( q6 Q4 c+ A' _5 P
- 4 S# c Y" h/ R4 r, }- B
- static tag_t ask_largest_face_interop(tag_t body_tag)
& w$ M. Z, F2 O( h7 R# U; G% q" d* E - {3 V) A8 P9 n: V" \8 k
- Session *theSession = Session::GetSession();
7 b4 y& W# F8 Q- J5 P5 J" J5 A - * W" n% h2 s+ u5 \
- Part *workPart(theSession->Parts()->Work());! i6 \8 [+ |1 O: L; a3 U0 t
- ( E0 H& _# Z! M! a( u0 C
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");$ O& t! \- o0 n$ E
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
9 N# ^6 T+ @7 L1 ~, v
8 G; U+ h2 e& n5 P: s' a( B- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));# z; D7 v8 p) `0 u0 X7 P
- std::vector<Face *> theFaces = theBody->GetFaces();& L8 } t1 k$ a% u
- 9 E0 |; l. i2 q! o
- double bigArea = 0;) j; v& \5 C% E7 A, E0 u3 k
- Face *bigFace;3 Q. q T |4 F. o+ I" r
- std::vector<IParameterizedSurface *> theFace(1); p% G" p6 r( v S" f; J2 a: _
- for (int ii = 0; ii < theFaces.size(); ii++)0 {8 L# |8 o" p1 f" q' z
- {
$ b9 w1 f. b8 [/ O: Z$ R - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
, N) ~3 D& I6 c% w* n# b- h - 9 |6 L$ y+ b# r; _1 s9 T* W
- MeasureFaces *theMeasure = workPart->MeasureManager()->
: Z2 D- ~2 \6 |/ N, [ - NewFaceProperties(area_units, length_units, 0.999, theFace);
9 |& {# y6 w: P# ^ - # ~$ @( |# r: d. ~0 c# y6 H
- if (theMeasure->Area() > bigArea)
. _1 Q! z0 [ k' r) i# N - {
( W" C% w: h: h0 R4 b4 _ - bigArea = theMeasure->Area();0 P( q, \ y3 _
- bigFace = theFaces[ii];
# [0 F3 ]: u w+ N9 `+ H7 Y) b: J - }! o) n1 m2 O6 S
- }, P9 P0 W& @! f5 D4 T s. P% R5 \
- ! \* y; f- D3 l8 X0 R
- return bigFace->Tag();- M7 ?6 [; Z- C8 f K/ V8 D( K
- }% @5 X: P9 o/ v! A5 L2 p
复制代码 k5 h* a, L6 a* y! q
4 b5 {6 p$ l7 S0 h
; r0 z: }1 E A* h- | |
|