|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
+ m. P: U' |! u" _7 }. xNX二次开发源码分享:查找体中最大的面积
" H# \! w0 Y3 Y$ P+ R* K8 I# m( R! L) a- A通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询7 C! L, i* ]2 w, [$ u+ b/ N3 S
1 I. S2 [8 [1 m0 O9 I; L* s: f* L
8 S. U. {! n. b" C8 D- #include <NXOpen/Session.hxx>- W) i% l3 V2 K- M5 q7 G
- #include <NXOpen/Part.hxx>
. ]( |7 A( B2 P2 E* _: s _* { - #include <NXOpen/ParTCollection.hxx>: x) F9 h; {% w. \. a3 v* t
- #include <NXOpen/MeasureManager.hxx>
) \! `8 e8 d: l - #include <NXOpen/MeasureFaces.hxx>
9 Z* V! `8 \, g6 {( ` - #include <NXOpen/NXObject.hxx>: n) ]. ~, Q B. Q6 `
- #include <NXOpen/NXObjectManager.hxx>
! j+ \& N0 J% M$ O& y - #include <NXOpen/Body.hxx>- ~' d1 H& U( u- _5 W
- #include <NXOpen/Face.hxx>
" l& {$ X) Y% K8 z - #include <NXOpen/Unit.hxx>
+ h9 F' L0 ^& \' P" g( Y) ` - #include <NXOpen/UnitCollection.hxx>
3 w7 |" F! i( D4 c& A' u - using namespace NXOpen;
8 U6 S% V& B+ {
3 V& c! a+ {! j$ Z+ x j" v- static tag_t ask_largest_face_interop(tag_t body_tag) o. l, r p, p; m/ E
- {
8 h Y5 c! i' S" _ - Session *theSession = Session::GetSession();
9 b% a' a9 J% U4 P' h$ `5 @ - ! g _( w ]. {9 g/ ]2 Q
- Part *workPart(theSession->Parts()->Work());
d7 C2 f0 q6 b2 T9 V' L; e
% q4 D5 E5 e! |, a+ v, q, X" z+ Z- Unit *area_units = workPart->UnitCollection()->GetBase("Area");1 B9 f$ f! g9 C
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
P4 u, j5 C# i2 B D, X7 D* G. y2 O - / w- M$ q/ q) j& d% `: P% ?* H
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));8 g( \. M$ l$ R3 w! l
- std::vector<Face *> theFaces = theBody->GetFaces();
0 q3 X" r; F2 V+ g% c$ e - 0 m, q b+ V/ ?2 r/ u( ?' F' S: \
- double bigArea = 0;: a- h* m, ]/ L; \" P6 W
- Face *bigFace;
2 A' H8 p* t" p N - std::vector<IParameterizedSurface *> theFace(1);& n6 k+ V; X1 d9 j, }* O& R/ d$ ~3 {
- for (int ii = 0; ii < theFaces.size(); ii++); }' u3 a+ L! q0 V4 u
- {
* Q; x- w1 w! i - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
0 a! u3 a/ `( Z/ g- E3 o7 C
+ ^& v/ n( u8 _' @% ?+ i- MeasureFaces *theMeasure = workPart->MeasureManager()->
r* g/ o( H/ d - NewFaceProperties(area_units, length_units, 0.999, theFace);3 i% q. Z% z. C: M
- 7 m6 x( z( F D3 Z5 M
- if (theMeasure->Area() > bigArea)
/ Y8 p; @8 j: g1 g - {( g; |1 X% ?2 ^; P
- bigArea = theMeasure->Area();
# D1 f/ t6 p2 y - bigFace = theFaces[ii];8 R. A, K8 V" b
- }
+ n; Q9 X9 _2 d& e. t5 V; x - }) h: v# N ?+ r9 S7 M4 M* x
) z" t7 l* P: q2 g; @5 x- return bigFace->Tag();
- C: G( c5 T/ N$ i - }
$ G8 r; O9 n$ y4 Q1 E: ~9 W' i
复制代码
+ E Q& ^; s! P, A- l7 ]) l, A# r5 l- }" L, ?
7 [! ?, S. o5 Y3 B+ x( n |
|