|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
! |2 i" M2 k, _7 {NX二次开发源码分享:查找体中最大的面积
( G* T" `" F* p3 f+ e! ]; D通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询" x i' r" H8 Y2 J7 V
7 \: N G% K+ P0 V: i( C
! o- l6 z- P6 t g& l
- #include <NXOpen/Session.hxx>
$ Q& {4 \/ D' z- |2 q: b) u - #include <NXOpen/Part.hxx>) P( b/ m" V& ?7 k3 ?; s
- #include <NXOpen/ParTCollection.hxx>
( n( v' y: c7 \1 `5 l - #include <NXOpen/MeasureManager.hxx>
$ }4 I% ~* M# l! W# C! X4 i - #include <NXOpen/MeasureFaces.hxx>5 |. Y! z: a- ~, W4 o. J
- #include <NXOpen/NXObject.hxx>$ x. V. o* s0 e F+ s( O
- #include <NXOpen/NXObjectManager.hxx>: e+ _: d5 ~6 g/ y+ p7 {- ~
- #include <NXOpen/Body.hxx># o0 j4 x5 {. @. R! Q; V
- #include <NXOpen/Face.hxx>
/ Z+ t0 U& z* s, F1 v - #include <NXOpen/Unit.hxx>. N* G* d q$ ^( I( M: s6 j7 z
- #include <NXOpen/UnitCollection.hxx>+ k* q9 q& g: o: P9 y
- using namespace NXOpen;. u9 T) }( r5 W9 Q0 B) C
$ m: H0 z- b" n) V- static tag_t ask_largest_face_interop(tag_t body_tag)
+ D& s8 X. l+ [; A7 m; I - {* X$ V+ E9 ]9 g( `/ p" _
- Session *theSession = Session::GetSession();" G1 v3 O" s2 V# N$ ]- b
6 T7 c9 u+ V1 R; Z5 S, v- Part *workPart(theSession->Parts()->Work());
}+ I0 b7 @ o! u6 \3 f" U
7 X0 f1 o# M" r& Q( |9 i9 m- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
2 S- Y4 o$ n, j - Unit *length_units = workPart->UnitCollection()->GetBase("Length");
3 K* @( Y8 F2 d/ w
) f9 S2 [* y9 n" F- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
% ~% U; W: P& p; @ - std::vector<Face *> theFaces = theBody->GetFaces();' R" N9 m6 \+ }; a& W+ a
U8 W! u( |$ b5 W- double bigArea = 0;
* u3 {% ^* H% V) d6 x, O% o - Face *bigFace;* z6 i( @& e. e/ p( a B% H) m
- std::vector<IParameterizedSurface *> theFace(1);7 Q, t4 P6 H% D6 G2 n/ V
- for (int ii = 0; ii < theFaces.size(); ii++)8 e: D% n, S7 A5 \- J" I
- {- M- q* Y# ^0 B* C& `5 N* R S
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);! l _* e/ H8 D8 w9 N, |
# I6 C! O6 G( B8 R* M- MeasureFaces *theMeasure = workPart->MeasureManager()->
5 o6 s- j. |4 D9 o% ~5 ^. n - NewFaceProperties(area_units, length_units, 0.999, theFace);0 [% s9 E. M, h9 c4 k. e
- - {1 G- a! c" `
- if (theMeasure->Area() > bigArea)
, X: s t' z/ M# [ - {
4 s4 C0 |/ G9 s: ? - bigArea = theMeasure->Area();7 i1 T9 S+ v" [7 V4 d1 q
- bigFace = theFaces[ii];
: T3 T, b( ]/ ~8 K1 @3 X6 W - }
& I5 q1 B5 ~2 h' r - }; e0 K; X8 e+ r
- 8 S. a" I8 W4 N* y$ o- {' y
- return bigFace->Tag();7 {- ^% Y3 O6 [% ~6 ~
- }
! M5 [1 Y; H. n; J/ g" m
复制代码
' I/ S! H4 q6 M1 X* h- m0 X& d$ r6 Y+ H7 j4 z6 i
4 t# v8 U6 P9 H( V f* b |
|