|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 J& {! g, p8 t5 P. n- w# K
NX二次开发源码分享:查找体中最大的面积0 p8 @4 i! |8 L
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
4 s4 {5 J* [' l7 B) @. p9 f7 r' T+ s4 T3 M/ `$ X8 W
/ q; { @/ f2 d& v
- #include <NXOpen/Session.hxx>( J0 r) x/ t" G0 N9 x& F7 I7 I
- #include <NXOpen/Part.hxx>9 t, p/ H: e& y$ o Q
- #include <NXOpen/ParTCollection.hxx>5 S6 z" S* J. r+ j# R2 {% r
- #include <NXOpen/MeasureManager.hxx># p/ X. J# I& y0 f9 p) x2 x$ |) k8 g
- #include <NXOpen/MeasureFaces.hxx>4 y6 v5 R2 a: }) r; Z# a
- #include <NXOpen/NXObject.hxx>, i, ?5 {! A0 c: |+ @
- #include <NXOpen/NXObjectManager.hxx>
4 ^' b, D* H8 n: g% ` - #include <NXOpen/Body.hxx>% B# J4 {# D$ C9 x
- #include <NXOpen/Face.hxx>7 A% c" ?6 J5 l% O( Z6 R- l# `
- #include <NXOpen/Unit.hxx>$ O) J" u3 q. Y% f, E' K9 m0 G+ t
- #include <NXOpen/UnitCollection.hxx>, ]: x6 b% w) i/ k7 @1 ^& Y( j
- using namespace NXOpen;8 }/ e. ^& K0 I) s. i- |/ ^! U
% }3 V+ C$ L+ x+ r/ O% b3 n- static tag_t ask_largest_face_interop(tag_t body_tag)% J7 ~* ?! ~# U2 I8 G
- {3 T* u) o# v+ p; z6 O) l' u$ j
- Session *theSession = Session::GetSession();: s. J& K- z2 P) s
- 8 M' ], X8 r& `, h
- Part *workPart(theSession->Parts()->Work());$ I; u8 `9 \0 I- u
" ^( B3 N b1 }$ P/ |' v4 Q- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
; R% L2 \( G# b/ e5 ^" h) W+ R6 L - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
0 V% ^, P8 }: b! }5 n& N; O - 4 o* `) \" h+ O% o
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));: V# t4 \1 W; y
- std::vector<Face *> theFaces = theBody->GetFaces();
2 Y: @7 z3 p7 A( ~, T - + n3 C4 x4 `7 O
- double bigArea = 0;1 L. w2 T5 L6 @9 n9 {+ {
- Face *bigFace;3 I3 ]4 j! @9 u. x8 b
- std::vector<IParameterizedSurface *> theFace(1);
8 k+ D4 M4 e$ D8 Q7 d - for (int ii = 0; ii < theFaces.size(); ii++)' q# F6 N) M5 ]2 G. W
- {4 W x* V! n p/ s
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);% E s! e+ D0 _2 D; j; c
- 5 E R i+ Y0 u9 g) }" Q1 |
- MeasureFaces *theMeasure = workPart->MeasureManager()->; H( k+ J' Q5 Y! Z+ X! B1 }
- NewFaceProperties(area_units, length_units, 0.999, theFace);
. D4 K6 E6 G. R, A - : K: S8 _. h) P6 h _, S
- if (theMeasure->Area() > bigArea)
8 I& A0 Z) N1 ~* k8 G7 U - {
! F" p/ [" N: j" k - bigArea = theMeasure->Area();* U9 N- U' ^; \* e
- bigFace = theFaces[ii];1 |. g+ C( K/ K9 ]5 ]$ x
- }
5 C% p7 Y' v& l0 Z- [% `* y - }. E- c8 E. `4 X8 p# ^) m
- & E* O# a" G( @0 g+ `' j; D
- return bigFace->Tag();
/ V8 I0 M' A X - }
& y" {9 G6 x2 g; `, G! k' ]& |
复制代码
* P( [" o. @" S6 D4 G! r, h' k# V+ A0 c) y+ H& R# {/ m
1 o2 K+ b5 g$ h; g4 @
|
|