|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
) _% R+ w/ Y4 S2 z. a- p p
NX二次开发源码分享:查找体中最大的面积% O4 y6 ~# J' E; S+ A2 n0 O( R6 e
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
# l2 t' m- x) w0 ]1 v! M" W) x V# T8 B) V1 g; I1 x1 Z
+ J$ J. M/ B. ?0 P# B' g) g- #include <NXOpen/Session.hxx>
/ ~4 Q6 B" d* o* H - #include <NXOpen/Part.hxx>; J5 e- u3 {6 j2 R4 X
- #include <NXOpen/ParTCollection.hxx>
) S' ^% |1 N% [% T' A/ R" p - #include <NXOpen/MeasureManager.hxx>
6 V1 G1 q5 m" t+ R - #include <NXOpen/MeasureFaces.hxx>% o# \" Z& c( ]* B
- #include <NXOpen/NXObject.hxx>: b6 q( d7 e* A9 ]) ?. r
- #include <NXOpen/NXObjectManager.hxx>
1 r3 B! U J7 o' h+ u8 x% ] - #include <NXOpen/Body.hxx>
$ u- Y5 y; N9 U8 V/ u1 j1 Z( M - #include <NXOpen/Face.hxx>
# b8 S: ?6 O7 P/ x- s - #include <NXOpen/Unit.hxx>
, R: p) o8 X! J* w6 d - #include <NXOpen/UnitCollection.hxx>
" b0 g$ r* Q8 M% g: l4 C - using namespace NXOpen;; p5 c3 q9 f- G" @/ h5 [0 P
+ Z5 o" |; q, i4 g" q) o- static tag_t ask_largest_face_interop(tag_t body_tag)7 H+ j; g- L/ m% F- v: ~2 |
- {. f' M. c5 \& Q" i9 @
- Session *theSession = Session::GetSession();
7 f( V3 O0 C9 d+ |2 T# |& ` - ( r; L, f2 e( N& N j. t' {
- Part *workPart(theSession->Parts()->Work());. o9 X; o8 ^& T2 `
- : q7 x- c! h8 x; ]
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
/ f+ K* P c) F - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
! j8 x: ]0 Y" J$ W( C
" L1 z' H1 U* Y& R# v( b5 B* \; f- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));' d' ? Y! D' [, t) I3 }% {4 b
- std::vector<Face *> theFaces = theBody->GetFaces();
2 @ i/ ]1 p9 s6 Z
. w& R1 u9 H: |' u& ^! p1 G- double bigArea = 0;
6 ~5 p- H* @* H) k: K' Z: m4 \ G - Face *bigFace;8 R$ J8 y9 J$ h1 S0 F+ u& T
- std::vector<IParameterizedSurface *> theFace(1);
, Q7 ^" E: p# |* O/ w - for (int ii = 0; ii < theFaces.size(); ii++); F9 O7 O6 q& Q. L. U( v
- {0 g8 O8 s e: x' ?% g) n7 |0 ]
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);( C. N) m3 x x
- # W) L/ g( {' c9 L3 d; M
- MeasureFaces *theMeasure = workPart->MeasureManager()->1 O9 Z5 b( y: T7 G. X, t
- NewFaceProperties(area_units, length_units, 0.999, theFace);
+ u* G6 D7 Y+ d7 W- Q- W9 R - & \9 o. @$ R% x/ c, L* E- s5 {
- if (theMeasure->Area() > bigArea)
( `4 L4 n4 W4 G" }; P7 h% \ - {9 G- c5 L( q8 ], o
- bigArea = theMeasure->Area();# a6 }# Z. ^3 R+ \- x. j
- bigFace = theFaces[ii];) T' {- i% z, |) `% B3 q
- }
' a" E7 B I0 K5 T/ N, c( N - }" \ V/ ?6 l/ a# L! @8 V1 I
- $ k: E, \+ ^" K( a% u
- return bigFace->Tag();
4 F3 A2 N" n" f8 n4 A - }
$ @5 `+ v* l' |5 C- A) ~
复制代码 ; r" ?- f! ?% ]; [9 T" |% r, e
& |* _% S3 h7 N7 b
+ \+ [, a0 i+ N2 V6 f/ p* i |
|