|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
* W7 {( \. v6 }& d$ w( V1 dNX二次开发源码分享:查找体中最大的面积
# ^+ _6 y$ g D- _' f/ H+ ?通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
8 Y8 o7 i3 |# _* [' d! P- |- h/ ?: N+ d
0 ?4 l( W% x9 `" W) h/ d7 a" x
- #include <NXOpen/Session.hxx>
! s& @' q3 g# x1 I) [" P. A - #include <NXOpen/Part.hxx>
& ?' q6 R& Z) n+ `2 e) z( v( v% y7 w - #include <NXOpen/ParTCollection.hxx>- w3 {5 z1 e0 R2 c2 |& ^3 O
- #include <NXOpen/MeasureManager.hxx>
' u$ l2 V2 h6 V j: { - #include <NXOpen/MeasureFaces.hxx>* x0 d8 r6 D0 Y+ i m2 |* a- F
- #include <NXOpen/NXObject.hxx>
; @, E* L5 Z: N4 i* u% p - #include <NXOpen/NXObjectManager.hxx>4 n" Z& D+ H) g
- #include <NXOpen/Body.hxx>
" t2 |, s/ j1 P9 x. o: r' M; D - #include <NXOpen/Face.hxx>8 p1 }- F4 w+ {+ K
- #include <NXOpen/Unit.hxx>
0 b7 m6 }6 \3 }* x5 b" A; Q2 ?! R - #include <NXOpen/UnitCollection.hxx>
5 O( ?, R( I- g - using namespace NXOpen;
# b, l) b) H5 {& L; m
9 x5 c9 y6 m5 o7 I- static tag_t ask_largest_face_interop(tag_t body_tag)) ?0 A3 K! F M/ J6 _) U; m
- {
- V, ?) z% R, C5 u3 H( \7 c - Session *theSession = Session::GetSession();
4 o% B8 ^ t* T9 k, n
8 w! }5 B' J/ D' }7 V- N- Part *workPart(theSession->Parts()->Work());
( M1 O5 ?2 p! P* z3 e
/ R3 Z; d5 B4 f2 h2 [$ k3 K- Unit *area_units = workPart->UnitCollection()->GetBase("Area");& Y& p0 {. M9 m9 n T7 A
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
( N& [% r0 }$ W; l6 L$ p) w: r# h - 0 h" ]" A6 v4 h* y; U; H8 S9 _3 k
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
9 V. D# [% [3 K6 K% a( E - std::vector<Face *> theFaces = theBody->GetFaces();
8 ^5 u5 D5 Y) U% f6 `
8 p+ q/ M) M0 o+ c5 `- double bigArea = 0;
" l: K9 H. T8 b% E' q5 i, H - Face *bigFace;% D0 ]& E- D- D5 t" V }. T4 u+ E7 x# T5 r
- std::vector<IParameterizedSurface *> theFace(1);7 `6 s2 g: l1 _" n& l B) J
- for (int ii = 0; ii < theFaces.size(); ii++)4 ?$ L# e( W% s# \
- {3 G# L! L* v% _
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);# _; C8 A% p, i2 [7 r
& j4 l6 u1 K+ ?5 b: t- T5 |1 B4 a- MeasureFaces *theMeasure = workPart->MeasureManager()->; W) o2 k# L# e: E& ]" m9 N
- NewFaceProperties(area_units, length_units, 0.999, theFace);
( K: t, q0 e% `4 ~ - " W% F2 H5 p! i! T5 z
- if (theMeasure->Area() > bigArea)
1 `9 J+ R% ?$ G - {: Z% l2 B' Z4 F1 [0 i: x
- bigArea = theMeasure->Area();8 U5 P+ V+ `+ P: P. u
- bigFace = theFaces[ii];
- ?. s) g4 k6 z8 M% s" x! M - }
5 J5 p4 _' ?- Z0 Y0 y; l& ] [8 \ - } A+ {, K9 a" ^% K9 @- a8 b
0 G% w' }; w1 K2 K- return bigFace->Tag();0 j ]2 q4 k% w5 ]3 G+ e1 P
- }$ {# u7 A/ x. m1 _! ]! p
复制代码
v$ F/ j* l& c8 [! v+ H$ A/ ~3 w$ t" `" n8 w* w9 l! h
1 G1 @. V1 Z, {: Y
|
|