|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; O. y% w/ n% e/ G, iNX二次开发源码分享:查找体中最大的面积
: g: }$ R% T; v; ?2 m通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
$ r& s8 h; R9 {6 E9 [& D' I! o4 G. w8 P5 x7 u+ G+ }! b$ _
5 s; ]8 e3 z8 ~* ~6 g! m- #include <NXOpen/Session.hxx>
! f8 L9 Q/ g. u. m O - #include <NXOpen/Part.hxx>2 _- X, t' C/ O& @8 A
- #include <NXOpen/ParTCollection.hxx>8 T( Q7 O7 Y" e( M9 {5 K
- #include <NXOpen/MeasureManager.hxx>" O! a+ s" M5 e B3 o& w
- #include <NXOpen/MeasureFaces.hxx>
! W- E" U' f) i5 N7 e4 M - #include <NXOpen/NXObject.hxx>& G2 T+ o5 L. E6 K2 u" L
- #include <NXOpen/NXObjectManager.hxx>
" j0 N$ D2 H5 H$ L$ D9 [; Z - #include <NXOpen/Body.hxx># m( K, G- q6 J3 P3 z1 Y& Y' ?
- #include <NXOpen/Face.hxx># k) M/ E! P. [; B1 X$ `
- #include <NXOpen/Unit.hxx>! V$ M, S3 Z* E) F: `
- #include <NXOpen/UnitCollection.hxx>2 `0 g5 U/ q* p' w3 W7 t2 C
- using namespace NXOpen;9 Q @, H2 L$ I
' S: o$ _" B8 |' r* H8 _$ c- static tag_t ask_largest_face_interop(tag_t body_tag)5 s/ l( t8 X5 Q& Y! T1 H
- {
{- T2 i2 v6 `' C2 @# Z7 ] - Session *theSession = Session::GetSession();
k) {% W6 x# V/ k - 6 w+ I$ c. T& i" D* _: \+ P) w
- Part *workPart(theSession->Parts()->Work());9 H, {+ ? K* L
1 }) ?( y2 P; `4 W2 U! R, i- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
- K# E1 e+ K# q. S7 c1 a - Unit *length_units = workPart->UnitCollection()->GetBase("Length");0 u' q. k; ^. J; K$ S" K
- 2 u( W- Z: R9 t& t! f7 n0 _# b
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
$ u9 I5 Q" J+ O - std::vector<Face *> theFaces = theBody->GetFaces();
7 g3 c8 t8 `# L4 u! x
$ T- u! r/ Z3 Q& [2 Q' ~) R- r- double bigArea = 0;( o6 H z3 ]. v* Y
- Face *bigFace;# y6 C! V. o, L. B( n1 Y3 E. c
- std::vector<IParameterizedSurface *> theFace(1);, A3 v) b8 H4 h4 Z( x
- for (int ii = 0; ii < theFaces.size(); ii++)5 A* K: I L" n i" a- Z# W
- {
$ @$ A, z& [ B/ F3 ]+ i( u - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);- w0 P: T- N5 z# t9 [
- ( N( ~8 x# P) Q
- MeasureFaces *theMeasure = workPart->MeasureManager()->1 t! D2 J6 f( m
- NewFaceProperties(area_units, length_units, 0.999, theFace);
, o e7 {, w& P6 r5 \9 x# A
7 w; X; |( ?' l! z- if (theMeasure->Area() > bigArea)
* O1 g% e% O# n. e - {( ?/ D7 v* ~' l6 {0 i
- bigArea = theMeasure->Area();
& r' a+ O4 u9 c& r! c3 y - bigFace = theFaces[ii];: Y( Q: `5 ~& y
- }
7 Y0 h$ p0 ]+ A& P W; j# y - }
4 S/ x1 Z# \) }$ s; r9 z - - R) D4 }/ `6 Y i" D
- return bigFace->Tag();$ n1 C6 |/ w! t2 C
- }
8 N7 `0 G# h5 t$ Q Q3 X* u1 g
复制代码 0 H8 T2 P, Z% i6 i% a
0 {9 m! S0 Y) F4 r7 a! J: R& {( Y) q8 h* y" e
|
|