|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
/ W; b2 N" o p7 m, wNX二次开发源码分享:查找体中最大的面积
, I( v B, `- N9 @9 w$ Y. E通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询. T2 }, F3 ^& Y- L" O
- V9 l& E6 W( h1 L2 i9 H E2 g8 x3 _ w3 T+ k) L
- #include <NXOpen/Session.hxx>2 q1 `" e; R# A' y/ ]5 c6 p
- #include <NXOpen/Part.hxx>
! G2 N) o: G+ d5 E2 G# j - #include <NXOpen/ParTCollection.hxx>
4 c J9 A/ B8 `- y# _0 i - #include <NXOpen/MeasureManager.hxx># m( r( } p8 `, K) o8 w. t
- #include <NXOpen/MeasureFaces.hxx>
0 a7 L& T% @7 F - #include <NXOpen/NXObject.hxx>7 h9 h: C, t! Z" {( a
- #include <NXOpen/NXObjectManager.hxx>
2 T- |( ^, d9 F! g) C5 u- B! P* b( X) ~ - #include <NXOpen/Body.hxx>
* J; V, e3 {; z- ~$ K% y! H - #include <NXOpen/Face.hxx>. i, R0 r* Z! x$ i
- #include <NXOpen/Unit.hxx>3 K7 n/ z# T7 S G( e
- #include <NXOpen/UnitCollection.hxx>
) ?: C& R( B2 p' U" Z0 s/ g - using namespace NXOpen;
8 E3 ^' g& x/ |2 o
; W e# ?, } p- static tag_t ask_largest_face_interop(tag_t body_tag)
% k1 ], `) W' R7 K& d" S1 w - {
4 u0 E8 x! q8 [; { ~/ _! l% M - Session *theSession = Session::GetSession();1 V/ G" L# z; X W
- n' g o8 I" e6 d) O" ~) m* w
- Part *workPart(theSession->Parts()->Work());
0 q" e+ L! m/ _6 ]& S - , z) c' Z9 W9 C; W
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");3 y# R9 k1 `. N7 l; G
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");; P( ^. M2 n+ `
# l' N% [1 k$ B) v7 ?! a$ i7 }- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));) y: e! j5 U3 P
- std::vector<Face *> theFaces = theBody->GetFaces();
. `( _ y5 A" O! _ - ! X& r3 d7 {; Y$ T
- double bigArea = 0;
! {. a/ q9 ]* m% T - Face *bigFace;/ [- _8 d) [+ Z# @4 ?1 Q
- std::vector<IParameterizedSurface *> theFace(1);
( V2 V9 z2 S: @ - for (int ii = 0; ii < theFaces.size(); ii++)
/ V2 l* B- M+ M3 @* Z/ G& ?: | g0 w - {3 o) E, R+ q+ {9 j
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);& ~/ A( G$ I9 \8 Y
- " |" h$ }% @! g! o
- MeasureFaces *theMeasure = workPart->MeasureManager()->( D. W: a2 f) q# ]8 C' U; f% O
- NewFaceProperties(area_units, length_units, 0.999, theFace);7 e" q3 Q! X' i6 m/ Q
- . R I3 i# z% n9 [4 E
- if (theMeasure->Area() > bigArea)
$ F) T7 F$ S8 o9 i7 u2 q) ~, l/ h - {
8 [7 u% }( ~+ L, M( G9 P0 u - bigArea = theMeasure->Area(); t j. |; q9 O1 `2 k
- bigFace = theFaces[ii];( }5 [* h' _- u, E
- }
4 U+ U* m6 S7 W& o) l; i( [' } - }
5 |# j: y" `% D j7 r6 {$ G - / \2 i4 W- j" l/ F { S: T/ k% ~
- return bigFace->Tag();3 d' m0 q! `2 P1 c, H- A
- }
; f# S$ |; W% \$ E9 k- W6 k
复制代码 * X" K# w/ u6 \' B$ S8 E
: M1 F0 d) w' A! W, Z) ^1 o- \
5 `' {- p5 x2 u7 k8 Q9 } |
|