|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
6 B% N2 Q4 o$ t5 P% ]
NX二次开发源码分享:查找体中最大的面积. \$ G, C) `8 S0 Y
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
; }8 b% t( i0 a9 k# R- ^, ]0 m9 h' L( M% e0 u( p* x F
: Q5 x6 N7 M S) F% ?! b; Z3 c
- #include <NXOpen/Session.hxx>
- E+ z( s0 T3 l - #include <NXOpen/Part.hxx>
+ ]; n2 @( {) B) k! R) q* [ - #include <NXOpen/ParTCollection.hxx>
+ r. s. s( d! x - #include <NXOpen/MeasureManager.hxx>
. N1 [0 \3 Y( U; n( S+ V7 I: f; z2 R - #include <NXOpen/MeasureFaces.hxx>/ q, u6 _4 d5 u1 H( ~0 s
- #include <NXOpen/NXObject.hxx>9 O. O$ \* i2 m2 j
- #include <NXOpen/NXObjectManager.hxx>2 F5 k6 k2 Y) C4 T7 K/ F
- #include <NXOpen/Body.hxx>
8 A% b: h! B5 G1 D4 I" h/ K& c - #include <NXOpen/Face.hxx>6 S, g6 ]& ~4 D& b5 V) C
- #include <NXOpen/Unit.hxx> M+ D- t: b, O, [) B9 X+ j: m
- #include <NXOpen/UnitCollection.hxx>7 u& M: D9 q- L6 x5 P
- using namespace NXOpen;' V0 ~1 [5 W* V/ C/ }
I- Z- i. t3 R+ ]0 M' V9 p) I- static tag_t ask_largest_face_interop(tag_t body_tag)! A5 {8 {5 b4 j7 G
- {
) e/ _( ^0 @" o0 X1 }# h9 I+ C) ]1 { - Session *theSession = Session::GetSession();' X+ x' E4 L" C
) K- D& K; k' p8 B& |: p9 @- Part *workPart(theSession->Parts()->Work());
) {: [. e& n* Z; b% ~! s - $ h" [( H! [/ g. r% Y
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");$ V) ]/ C- E" Z6 u: Z& u# @
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
7 D Y8 q/ r. B# N1 F/ @# C8 k - . H0 x0 d/ X" V" x/ s8 [0 K
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
* `& h0 S3 ^5 n) a* T - std::vector<Face *> theFaces = theBody->GetFaces();- f, R- H& o& Q( p2 K! T
1 q8 G# S# P0 v5 z6 q) g' ^1 y9 Y- double bigArea = 0;
: P& h1 R1 h k5 d) R! [ - Face *bigFace;
' [3 j5 }8 D% e! N - std::vector<IParameterizedSurface *> theFace(1);- J' H2 t6 p: E3 w6 |. M1 k9 M) B
- for (int ii = 0; ii < theFaces.size(); ii++)5 z$ [2 f' {: s4 ] R
- {
, K3 n; g, z# N# P3 Y# \' i* o - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
! f) z$ n& n$ F1 t" s8 I1 w; q6 d - 5 f4 x( @7 z. O6 x
- MeasureFaces *theMeasure = workPart->MeasureManager()->
0 M# O" f$ y* D5 z - NewFaceProperties(area_units, length_units, 0.999, theFace);' L: A" t/ G" e
- $ l' W" A3 Z8 {, X5 C% `2 F# w
- if (theMeasure->Area() > bigArea)
, t5 H: N- Z8 r. m3 O - {. _0 t+ i0 F. F& w+ O- [# z" s" X w
- bigArea = theMeasure->Area();
1 z& A7 r. t' v0 J) o" b - bigFace = theFaces[ii];
$ _! d, Q5 @1 d - }
' E* p5 Y7 ]* J K - }/ y; v E3 M/ C& l4 h$ X3 {
- . ?8 R) ^ N1 R+ G5 F! I
- return bigFace->Tag();# ]3 H9 Q1 E4 q) i/ T
- }
) T7 R1 E- Q8 W/ M. C
复制代码
$ x3 X% T% K8 r* U4 k' s; @
3 z5 y& K) q# B1 P2 g" a/ E8 v& X# j5 A: o, A
|
|