|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
2 D( }8 A( X7 L7 Q. K
NX二次开发源码分享:查找体中最大的面积5 W' l! d; { y& H { F; n: h: u+ e8 f( l
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
3 m/ ~& p9 o* r
8 a" g+ {% \) U4 [( [- m8 h+ @9 D% r$ \- w! q( E& T
- #include <NXOpen/Session.hxx>" _0 ^6 b5 j( ^ O2 M
- #include <NXOpen/Part.hxx>
) S* h& V4 z2 V7 s" y1 Y& a* K5 q - #include <NXOpen/ParTCollection.hxx>
; O; T* q# Q! l$ Q5 E9 } - #include <NXOpen/MeasureManager.hxx>
0 d4 ?4 P( ~* h - #include <NXOpen/MeasureFaces.hxx>
( I/ X1 q) Z4 r: a - #include <NXOpen/NXObject.hxx>
# m# W* _8 k1 a) H& ?/ |7 a - #include <NXOpen/NXObjectManager.hxx>2 c. v+ P3 B x: T
- #include <NXOpen/Body.hxx>
D* u: U$ I6 ~% v& Y# A; g - #include <NXOpen/Face.hxx>/ @" ]! Q) Q0 O7 s7 C. {, t; h
- #include <NXOpen/Unit.hxx>( K0 S, S9 R/ w$ R! y
- #include <NXOpen/UnitCollection.hxx>
) X' I8 |9 g5 l; \/ q8 k% \+ r+ u$ v - using namespace NXOpen;, M% E2 F( n& C" W' r& K' m
4 I% Y# M3 Q1 N/ ~- static tag_t ask_largest_face_interop(tag_t body_tag)$ F0 h4 j0 @, C4 C* `% x
- {/ n q2 w; D" F2 x# d/ v" x/ r
- Session *theSession = Session::GetSession();# |+ o7 \% I$ p7 q
- ]# C7 ^* f8 @% |7 ~% @ t0 z$ C
- Part *workPart(theSession->Parts()->Work());
6 G% V7 F3 ~9 P' I - - X, H6 z$ ]$ o3 f) V4 t+ ]! b
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");! N& |) O' D' f' X N# d4 l
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
) i1 s0 T8 D u; M5 M# K
& t9 W6 c+ i" t: y9 S8 O& E- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
z2 ]' W8 \- y$ N' \8 ^ - std::vector<Face *> theFaces = theBody->GetFaces();4 `5 @& P/ S* ?
- s0 m$ `* I8 P4 g ~: A2 M8 |* e- double bigArea = 0;
1 A5 D) G+ |- m Z' S+ x - Face *bigFace;) n; I0 t0 h: c- @+ Q
- std::vector<IParameterizedSurface *> theFace(1);* j- N5 P! U x- [
- for (int ii = 0; ii < theFaces.size(); ii++)
( m7 H J9 p; S - {
& M& K0 e' {0 N; S8 { - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
( |- Z |; I6 y - . [8 G* V. r- B2 x- \* ?# r
- MeasureFaces *theMeasure = workPart->MeasureManager()->
$ F) B+ r3 k7 Z" M- \( ?4 G5 | - NewFaceProperties(area_units, length_units, 0.999, theFace);
0 ^& C' d" q. n' b& ~ - . L& Z/ Z4 q) g4 Q
- if (theMeasure->Area() > bigArea)
: o# K4 m& W: E* A% ? - {
1 d4 ~. T- G7 x6 [ - bigArea = theMeasure->Area();: h( L0 _" [+ }9 Z) o- ?5 q
- bigFace = theFaces[ii];
& _3 O, a0 I8 a) ~( k - }$ K7 B( K6 r6 L' L8 J6 }/ r$ B5 `
- }
8 y9 c' C6 q, C- `! j; w& _* R, q - / X& k1 g: O3 x- [( C; D
- return bigFace->Tag();
& e0 K8 P4 T/ R5 A% b - }- e# l$ _* p6 q6 J1 x6 Q
复制代码
! s l M7 Q$ x% U8 l k: }' g
/ G# k; a: v) w
% Q5 y& S. p b1 C9 Y+ D0 Z0 ] |
|