|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
; t$ q0 }) S' w YNX二次开发源码分享:查找体中最大的面积
, P+ h1 S( j* C! z1 o! |9 |' m: S通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询5 J8 Z, @$ n1 k: y8 Y3 B& s* B# r
+ ]* q+ {6 L; ?' @2 v
4 l0 R& H6 y+ X5 J& y) P- #include <NXOpen/Session.hxx>; `; w0 h; M: y9 Y5 J7 t
- #include <NXOpen/Part.hxx>
7 _& C- D1 G& ], a, h1 [ - #include <NXOpen/ParTCollection.hxx>
) ?8 W) s# o" G3 s/ @! W - #include <NXOpen/MeasureManager.hxx>: E! p- N2 X$ Y0 F
- #include <NXOpen/MeasureFaces.hxx>
* ~% |8 {4 F3 i/ ]. Q" L - #include <NXOpen/NXObject.hxx>
; C: r1 Z% o3 Z8 o& N @" P - #include <NXOpen/NXObjectManager.hxx>4 X: ]2 K7 w* ?8 q/ J2 M
- #include <NXOpen/Body.hxx>5 o2 U9 i1 W& c9 \# E3 e. S
- #include <NXOpen/Face.hxx>" f* w+ ~% C# |! F7 z; B6 B
- #include <NXOpen/Unit.hxx>" B7 g( c% w! A% v) N6 U/ t. f
- #include <NXOpen/UnitCollection.hxx> L6 w8 e0 A6 P. j) c4 u; H
- using namespace NXOpen;
) d1 l7 {+ e* K: v6 H - / }5 A& a. F& `* w3 U
- static tag_t ask_largest_face_interop(tag_t body_tag); L1 X: L" c. H7 S7 ]
- {( g( w" Q" a" k; ]+ U; I! ^
- Session *theSession = Session::GetSession();
4 o/ T, n9 j* T) ^% y
; Z% i. t% V- {" z" m, E, ^- Part *workPart(theSession->Parts()->Work());
$ e7 C) K8 R7 ~ - : C+ z- y' o* l3 D( H
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
2 \5 C. r0 }' o7 |" s8 |& Q - Unit *length_units = workPart->UnitCollection()->GetBase("Length");: \6 c i! c& v( X4 Z& H
T0 g' u" \- |' {# c0 N- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));' i6 y. Z, O9 T% H2 A) U2 m& J3 `
- std::vector<Face *> theFaces = theBody->GetFaces();
7 _* |/ ^5 \) |
$ D) ^/ g7 j7 \$ C' _8 R- double bigArea = 0;
8 y' g- r5 t2 Z2 s1 [ - Face *bigFace;
- i' j2 M' X) r2 a - std::vector<IParameterizedSurface *> theFace(1);0 c" D' `6 F- ^5 p5 A0 j
- for (int ii = 0; ii < theFaces.size(); ii++)
- j A, O8 }$ y$ _: I8 s, _ - {
: @# O# q* y7 C7 x - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);
: \$ P( X' H0 U9 D# m% W2 O0 O
0 [! s5 ?4 J# U; h5 P* b- MeasureFaces *theMeasure = workPart->MeasureManager()->
& ~& s2 e; x- R7 F - NewFaceProperties(area_units, length_units, 0.999, theFace);; {# |2 T( r8 m/ }6 k6 J/ O6 Q
- ( q8 m- k# D9 Z" H/ B
- if (theMeasure->Area() > bigArea)
2 _ U! C4 p: C O - {
. O# \) G3 W J* b/ I - bigArea = theMeasure->Area();
- {( ~- n. @, Q - bigFace = theFaces[ii];' ^1 P, C' {6 ?5 E
- }8 {" A! c7 v# N5 T
- }: ^: P/ y# @* q
) W0 I; W! f! V" j' U4 D4 V- return bigFace->Tag();/ | A% W2 l' n& `& ^) f/ D9 X: Q
- }
- r# N4 A" `0 r/ b
复制代码
" ? f3 f# q. ?- `% v1 x- F) j
" S% q3 f, r2 g( S) h" N
6 [* N+ J) O; H, b4 W' Q" } |
|