|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
# \4 i U5 M+ Y3 x" x& K0 ^) w$ KNX二次开发源码分享:查找体中最大的面积
1 \2 Z: `4 p: y' @. ] R' [" f z通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
l" \4 t1 j* E# u5 `% v7 b: ?( d; S1 e' N
1 w- {- ]/ J2 g; n9 m& t: y% \- #include <NXOpen/Session.hxx>1 q4 [3 s; f8 W9 ]1 U
- #include <NXOpen/Part.hxx>
]4 v' _8 d; W0 S - #include <NXOpen/ParTCollection.hxx>
; R) L, k, x* j* ?& z% x. h1 _( N! z - #include <NXOpen/MeasureManager.hxx>/ c+ K, p' W8 Z0 D% E1 R# P4 D
- #include <NXOpen/MeasureFaces.hxx>. k& S/ a2 n: I1 I
- #include <NXOpen/NXObject.hxx>
/ A9 w4 r3 e. ? - #include <NXOpen/NXObjectManager.hxx>
7 s7 j! w0 ^1 n, h- B8 R - #include <NXOpen/Body.hxx>
) ]2 v* E9 O6 o) r: u8 k3 u, y - #include <NXOpen/Face.hxx>
( ]! w+ f1 m7 J; j - #include <NXOpen/Unit.hxx>
1 B/ g- U4 W8 m& Z4 \3 x - #include <NXOpen/UnitCollection.hxx>
; u( H+ p" S! \4 o1 R' @/ m - using namespace NXOpen;
" V0 G8 G9 h9 m/ V2 @$ S
9 k) b: C1 v z: L& x: r ~- static tag_t ask_largest_face_interop(tag_t body_tag)* }% [1 s0 k' p7 r
- {
" J+ x0 F& C/ e+ t - Session *theSession = Session::GetSession();
; U$ O! N; @. d - % j+ q. i/ ~8 X/ a( Y6 O0 w# x& S
- Part *workPart(theSession->Parts()->Work());
# k0 x; @. g5 c8 P# W1 |# P
0 W, r0 Q4 M0 h8 W( g1 ^- Unit *area_units = workPart->UnitCollection()->GetBase("Area");; p1 F) f( s7 N$ b* A
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");; R# H7 U% p2 c! z! T& T" x; {
- ) V' @# U2 f$ Q( `1 c6 Z/ w, N! g
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
5 H; | Y1 k9 T) H* Q- w; ^ - std::vector<Face *> theFaces = theBody->GetFaces();2 D% E3 ^. ~0 q. s: ~. E) k
& ?9 a) L2 V ]- double bigArea = 0;, H: A% S. @- y
- Face *bigFace;; t. U/ e$ e8 E- n
- std::vector<IParameterizedSurface *> theFace(1);% M! J* y4 N2 s8 v) |1 e
- for (int ii = 0; ii < theFaces.size(); ii++)1 }5 I) R% F* S# A$ @
- {! | y {$ W9 X# c8 Q& X
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);) \! S) y- P/ L3 [7 S: I
4 h- `" @6 E3 L- MeasureFaces *theMeasure = workPart->MeasureManager()->8 k' R; G, M1 X/ A, W( U9 {
- NewFaceProperties(area_units, length_units, 0.999, theFace);+ V/ u2 p+ Z$ ]6 a, o/ k7 W
\( \0 @6 D6 j" r3 [ h- if (theMeasure->Area() > bigArea)
" |& p/ ^" G( o6 H+ F4 U! p" G - {9 [+ \8 J; A" o, o5 W x/ N1 d% M$ t
- bigArea = theMeasure->Area();
. i/ E3 G2 S$ J0 J4 [+ t - bigFace = theFaces[ii];
/ ], A8 K. \/ g - }5 u/ c" n! s2 S. q1 z j
- }
- q: L) N' s+ _# U, v
$ E9 j/ I1 K! |- return bigFace->Tag(); G0 {3 {6 R' R! w$ S( I% ~
- }0 `2 i/ f- N% W6 [' c: D; R
复制代码
# o J1 s' V8 @/ f! [3 o2 J! ~! Z" E: m4 S
5 H2 P; G P8 d; C" O9 X
|
|