|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
! M( f5 C( N/ n$ f5 E
NX二次开发源码分享:查找体中最大的面积6 r1 I7 B( A% N- O
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询 y) F7 D& r6 j! _$ J9 B% q
6 r8 \3 I. t! i3 A7 E2 i& v- U1 J7 P
. \+ T) r% u7 r0 E- #include <NXOpen/Session.hxx>
m7 {/ A& V# r: k. [ - #include <NXOpen/Part.hxx>
9 h2 {! l+ S8 r3 A; N3 i - #include <NXOpen/ParTCollection.hxx>. ^, `: l0 R, e
- #include <NXOpen/MeasureManager.hxx>5 ^" ]% G3 ~9 O
- #include <NXOpen/MeasureFaces.hxx>" w/ V- b2 q, b
- #include <NXOpen/NXObject.hxx>
" M# S* ?# g4 t4 _0 S - #include <NXOpen/NXObjectManager.hxx>* Z8 H$ J/ y- `$ g
- #include <NXOpen/Body.hxx>
$ Y7 E( N( l+ j9 e; c! j - #include <NXOpen/Face.hxx>
: V! h- |, ?( d! [$ E! O - #include <NXOpen/Unit.hxx>
" w9 j9 |" ?1 N* u. i( e - #include <NXOpen/UnitCollection.hxx>, s. R8 `3 C6 d; H
- using namespace NXOpen;! o7 O; M& B& \+ s1 k0 q
- " y9 z1 z0 \1 c+ j$ t
- static tag_t ask_largest_face_interop(tag_t body_tag)
# |: D, H* t/ u: f - {
+ E5 e8 Z9 D. w- n9 f - Session *theSession = Session::GetSession();! O# N; l/ D4 o
/ {- v/ m: K) f' R4 {1 p- Part *workPart(theSession->Parts()->Work());
% c2 g" g) F. o6 n. g - ( \' v3 y# m; Y
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");+ [, |0 {% {6 j7 V1 w) Q+ i2 s) d
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
p- j/ y; h' d& W - 3 P! Z) ?4 b8 A s
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));3 r, s0 o) [6 a A( [% `, {
- std::vector<Face *> theFaces = theBody->GetFaces(); a% {1 O$ V0 ^1 @2 T" s/ J* Q6 X/ A
2 n/ i# d* F1 x8 w3 Y- double bigArea = 0;
7 B* F! v: U0 n9 j8 p: u - Face *bigFace;
5 C0 A6 I/ s5 Y4 \ - std::vector<IParameterizedSurface *> theFace(1);
5 h" K7 L# s, P& Q - for (int ii = 0; ii < theFaces.size(); ii++)
; v2 O, C5 U% s2 @: c - {0 y! T% Z$ L/ l* Y' j( L! v
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);3 [/ r( i5 Z- c0 G1 ^# b6 a
- * s/ _3 P( l* r
- MeasureFaces *theMeasure = workPart->MeasureManager()->
- ?9 u' e6 i5 s9 ?0 g - NewFaceProperties(area_units, length_units, 0.999, theFace);8 P5 o6 p! \* Y3 d" W2 l/ O
- ' m( g8 A& y" @' k% F- F5 P
- if (theMeasure->Area() > bigArea)
% y2 q7 I5 W9 x" ~0 Z - {
* s0 P0 N) m3 y6 I0 f" \ - bigArea = theMeasure->Area();
& S6 Y# E; r8 _, h; ^: N P - bigFace = theFaces[ii];
/ K8 J0 n& |; g! y4 h - }# P5 `$ ^4 v$ u2 H4 Z; c# @
- }( T0 G! Y: D& P
- 7 f& O, g7 |8 [0 B
- return bigFace->Tag();
: i1 x8 l- t2 Z$ {9 e- ` - }) s3 p* v+ Z# C) k# x' M
复制代码 # k7 t+ V* }) X) i; A5 f
' j, H7 C ?( b: J, B- ?
& `% }+ Z/ K: M( W. C
|
|