|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
2 V( E5 y- ]8 [1 J" q+ p7 j. b
NX二次开发源码分享:查找体中最大的面积+ `9 v- I' u" Z0 O4 u3 f
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询# f" [8 |- p+ [
- c- ?: `! I& {/ l( P( J
. Q( S8 d! P; i% H. S6 x. r- #include <NXOpen/Session.hxx>
4 }3 `$ Z2 {( J - #include <NXOpen/Part.hxx>
& G6 u8 C+ Q- j M$ i2 n, U - #include <NXOpen/ParTCollection.hxx>
! v5 e$ F5 Z7 i - #include <NXOpen/MeasureManager.hxx>
2 Y! b! J. u! I& B - #include <NXOpen/MeasureFaces.hxx>
8 B* c# l' Z4 T6 y( M; X8 N8 R - #include <NXOpen/NXObject.hxx>
8 \8 Y" R5 a7 Q - #include <NXOpen/NXObjectManager.hxx>
, ^8 J, d( }) U) m( W' `3 { - #include <NXOpen/Body.hxx>! A' T/ M& R% D3 R1 ^' ?
- #include <NXOpen/Face.hxx>
g u0 m2 |' W# L' E0 e9 f$ j! z - #include <NXOpen/Unit.hxx>* } i7 w+ r9 j" R9 Y* ~
- #include <NXOpen/UnitCollection.hxx> N- _4 Y: S, F2 G- V3 b5 y
- using namespace NXOpen;
; A$ I3 M } q$ r5 V, h8 [ - 3 T$ r0 K! M! `
- static tag_t ask_largest_face_interop(tag_t body_tag) j0 N. ?) F5 t
- {
0 M' W0 F+ T/ v& Y* j& e( J - Session *theSession = Session::GetSession();7 M* T1 M) u% f* N ~* Y; O3 J
( f( X7 o' I* u" o: K- Part *workPart(theSession->Parts()->Work());
' u. F1 J$ w7 X/ }. {
4 L9 G9 G4 j# b5 Q( |" `3 \. m- Unit *area_units = workPart->UnitCollection()->GetBase("Area");1 R3 D/ \9 I1 p: V
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");2 W, g7 F# m$ |" q
* R" b% \ T: }- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
$ G+ \0 A) p& @5 F) d - std::vector<Face *> theFaces = theBody->GetFaces();, A7 E% Q5 l2 S
- % T2 T2 i# _- d( V, t- g( I
- double bigArea = 0;
2 u' j0 I$ b9 S) C2 o - Face *bigFace;
$ ^* H% l5 m$ w, @- n/ A. e7 d - std::vector<IParameterizedSurface *> theFace(1);+ d; r0 S1 v+ X
- for (int ii = 0; ii < theFaces.size(); ii++)
% m _$ A; u3 D* ~ - {/ w5 E5 ?9 u3 [6 U; T, t8 E0 L
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);. [; [9 q. f$ D! n' m1 W1 \& |( z
! S0 ?" D: h: ]- MeasureFaces *theMeasure = workPart->MeasureManager()->1 I% t- O* u, z: I4 N% ?5 Y
- NewFaceProperties(area_units, length_units, 0.999, theFace);
2 G; A) Y! i" p. n/ \
, r0 }4 g$ \8 |/ z3 e- if (theMeasure->Area() > bigArea): |) `# j+ x& Q4 N' L- J
- {
9 F/ r" O% d: T6 f - bigArea = theMeasure->Area();
; @1 A# k4 R# O - bigFace = theFaces[ii];: E* n$ O9 \, r
- }
8 g% J" `5 w+ x$ }7 S7 j) Z - }
" f/ {- [) }4 Q8 z
8 K _( \2 p. f; g- m- return bigFace->Tag();) ` k& d j5 \& S7 ^8 R \0 G
- }7 n. r: K1 |$ o) r# E0 Z4 x
复制代码
9 F0 m# S _' t7 V! W& k# B) z- |- p4 ~0 q3 p& q
0 d: w8 y% z' z6 O8 Y- G) }5 h
|
|