|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
& Q6 }1 `& J0 D5 t' Y0 x6 Y3 M
NX二次开发源码分享:查找体中最大的面积
1 I6 P$ ^' A' U X通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
6 L9 k3 b5 X& S5 l8 y, D/ c9 \) H8 | P3 R, N6 X: ?0 c( p
& _- `9 h0 f7 |% V9 \% b- #include <NXOpen/Session.hxx>) f+ `. [& Y3 y- Z7 k9 o
- #include <NXOpen/Part.hxx>
- |4 O. C! k9 o) I H) c3 d - #include <NXOpen/ParTCollection.hxx>
3 ^4 b6 l( r4 o. u - #include <NXOpen/MeasureManager.hxx>4 u# i& g$ V- W
- #include <NXOpen/MeasureFaces.hxx>
5 y6 v9 o4 v# Z3 p7 P0 D - #include <NXOpen/NXObject.hxx>3 N* n" p1 B- D2 m# r5 F! o
- #include <NXOpen/NXObjectManager.hxx>
% ]* A. N" b8 d - #include <NXOpen/Body.hxx>' u$ g& K! y1 a# \/ ^
- #include <NXOpen/Face.hxx>
7 e1 P2 u* T, f" F - #include <NXOpen/Unit.hxx>' j3 P! z4 s9 u$ @- S0 e
- #include <NXOpen/UnitCollection.hxx># Q" Z2 f( a6 D X/ H0 _3 P
- using namespace NXOpen;
1 c, K7 E3 J* X( b
- D/ P3 [) D' \4 i$ P8 U: u- static tag_t ask_largest_face_interop(tag_t body_tag)
0 }- ?$ [$ A6 c+ h+ |4 m$ s - {7 V+ W k! q% h
- Session *theSession = Session::GetSession();8 Z8 l0 C7 Z0 |( l
- 2 h2 r. P5 M; h" l$ F
- Part *workPart(theSession->Parts()->Work());8 h3 \. j8 m1 F, ~0 Q% A. x6 d
" s- R; L! D& B! d0 J- Unit *area_units = workPart->UnitCollection()->GetBase("Area");! {$ t/ R, t5 Y- x/ N0 d
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");) N* R2 h% s4 V
- 3 e: j8 |6 P; \) h: V
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
+ P$ F# w% Y9 `5 J - std::vector<Face *> theFaces = theBody->GetFaces();( f! @3 U% _% z
- : E, n5 s0 v/ K' M% a
- double bigArea = 0;! f. m t! C8 n9 d( f
- Face *bigFace;5 ~8 o+ r: Y) w3 g
- std::vector<IParameterizedSurface *> theFace(1);9 T& u: O% S) B; }( F3 c7 E
- for (int ii = 0; ii < theFaces.size(); ii++)
3 f$ x% B+ M3 n4 j& N - {
* T2 \$ r) y. ?9 f+ w - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);/ A2 a! L. w2 b; v: ^8 D
/ q1 ~/ H. @! C) ~- MeasureFaces *theMeasure = workPart->MeasureManager()->$ Z! K7 |( }! e; Y) d
- NewFaceProperties(area_units, length_units, 0.999, theFace);
: H3 @, _/ T/ J' p( t& j9 v4 L
* X3 p x F0 h6 s! J5 M+ f- if (theMeasure->Area() > bigArea)0 v* \0 a8 y; X3 T
- {. A4 e/ X% e% [( {: K3 c
- bigArea = theMeasure->Area();
, k8 J' J0 y& \" U+ D - bigFace = theFaces[ii];
3 y6 q. z: R: \- \: K _ - }# S( l; Y, a& p5 v: K) L
- }+ a# `6 d/ s) d1 U# a6 m
- # F; r" _' v$ S$ R
- return bigFace->Tag();7 I3 w/ B8 E$ ~+ v5 y+ X7 E
- }
6 ]! m2 Q8 s0 ^* C, h$ w, K1 e
复制代码
1 J2 e+ g& |3 q4 ~1 e" Q
6 P( T; r4 S8 e! L" K, X% n7 C8 E5 G+ b" M) ~
|
|