|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 J4 [7 y8 k; X) F
NX二次开发源码分享:查找体中最大的面积 Q" l3 j; Q, ^. o6 `1 g: i' @
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询' d# N7 o& j4 S
6 ]7 F# O; o) _( c6 `& T- G0 C! E1 h* O# K. z
- #include <NXOpen/Session.hxx>
1 d. S1 B- U; F" Q! ] - #include <NXOpen/Part.hxx>
1 e' H# N0 ?; t - #include <NXOpen/ParTCollection.hxx>& {3 O+ z& n- O2 D1 b/ F
- #include <NXOpen/MeasureManager.hxx>
/ M5 H) C( e4 Q9 t) E - #include <NXOpen/MeasureFaces.hxx>
: o2 u: I9 R( J! V- R7 S - #include <NXOpen/NXObject.hxx>, w9 b/ E) ?$ P& `3 t
- #include <NXOpen/NXObjectManager.hxx>8 F1 l5 k/ x, L0 ?. S6 `
- #include <NXOpen/Body.hxx>
. u9 {6 o @' S" I - #include <NXOpen/Face.hxx>4 ]. f7 |( B* s( g4 `; [4 [
- #include <NXOpen/Unit.hxx>5 y& @! i, W! i A7 M8 a4 e
- #include <NXOpen/UnitCollection.hxx>
, ?# |4 @. n/ j0 D5 n- h - using namespace NXOpen;: _' Y2 b$ k+ Q, F( @
/ R4 N: i3 @0 n# z! R3 }# J- static tag_t ask_largest_face_interop(tag_t body_tag)1 G( G8 r$ x! j! M0 M, V
- {
/ Z2 |; z6 |/ m" ?; s - Session *theSession = Session::GetSession();
9 g. @. T: q v- o
2 Q8 R! T% P. f4 ^" |! r" _6 O- Part *workPart(theSession->Parts()->Work());
- }& R3 D* g# d" X
+ a0 J0 Q5 I- s7 ?7 t9 J- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
! j% n7 I" I+ [. j - Unit *length_units = workPart->UnitCollection()->GetBase("Length");" ^$ y* q s: L3 j' W& m
- * M; v9 E: I+ ~: c: o" `) r+ G. @8 z
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
! s \; u/ h: _" M - std::vector<Face *> theFaces = theBody->GetFaces();
* ?; U0 ^/ v% w+ t- C- I - ) q- A; k3 F9 g2 Q
- double bigArea = 0;
7 L* ~9 p5 d. A: c - Face *bigFace;
, w4 A2 V# D# I+ W4 F# {4 o; O6 Y - std::vector<IParameterizedSurface *> theFace(1);2 X" h) Z3 I/ k" g
- for (int ii = 0; ii < theFaces.size(); ii++)
5 o- x; H: H5 [( q: d2 \$ U, c - {
! z L5 |8 f9 a k+ J/ e - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
. f! b6 R( G2 B' }2 i6 r
# n- t D; t* D2 l1 Q: j" K- MeasureFaces *theMeasure = workPart->MeasureManager()->4 Z. d) H5 E$ T' }5 k, k
- NewFaceProperties(area_units, length_units, 0.999, theFace);
* @, x7 L' `+ w9 F/ B9 y) z, s - 1 O* l7 f$ n! S% b
- if (theMeasure->Area() > bigArea)
! t4 h: C2 V9 d4 d3 _' Y - {
7 W) J& s/ y: i' t% \' W9 R* f - bigArea = theMeasure->Area();: C$ U/ {# V, a& O
- bigFace = theFaces[ii];0 c% j5 u3 R% e1 s
- }' U5 H+ z4 e# y0 Q5 U
- }
i& L* Y. {2 Y" R0 @; }
9 ]7 Q- f! K( x/ }9 Q# J: f/ z- return bigFace->Tag();
$ z8 `3 K: D- Q8 G - }
8 P; `7 W8 ~" Z# ? q
复制代码
9 G# b3 M' ?7 z9 t7 c
4 [4 c* D8 e) g" s$ w, Z$ t6 v$ W! }% \! r
|
|