|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
! ]& [) U |9 Q; |4 t0 Y3 p2 v+ v
NX二次开发源码分享:查找体中最大的面积' \/ W% f- [4 S% e+ Q
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询( S& j6 ~1 c7 L* S/ X
9 y; _, H- c, Y2 ]% h0 e- o6 W+ q' q8 e+ V
- #include <NXOpen/Session.hxx>
6 A8 `: b5 [, J* u* J4 A - #include <NXOpen/Part.hxx>
) D! h$ z9 W* ^ w+ O+ F6 X5 A - #include <NXOpen/ParTCollection.hxx>! R [8 a" a- d7 X8 C0 b% x
- #include <NXOpen/MeasureManager.hxx>! U3 m" n! e( z' \$ o6 p
- #include <NXOpen/MeasureFaces.hxx>, Y7 G \4 U. q1 V6 ^5 r
- #include <NXOpen/NXObject.hxx>( W& _6 k; W+ E1 R8 ]
- #include <NXOpen/NXObjectManager.hxx>
0 `" B% N9 [3 ^0 g8 i) @: D z - #include <NXOpen/Body.hxx>
, V; E& f' e, Y$ A4 N M9 g/ i - #include <NXOpen/Face.hxx>) W, v& R9 |' o9 C# g ?$ t9 |
- #include <NXOpen/Unit.hxx># \3 T, g ^- Y' [( ]3 S% s
- #include <NXOpen/UnitCollection.hxx>% F, Z+ k" l2 L' ~
- using namespace NXOpen;
( }) J! P( D R. }* n6 {6 f- t/ H% j
% C0 C7 [3 F+ ?9 O, ^$ Q- static tag_t ask_largest_face_interop(tag_t body_tag)
+ x3 M" Y8 {" M: b0 L) }! _/ o - {
+ @# l7 g S) M; l - Session *theSession = Session::GetSession();/ N# c& @4 E, H! G# I
- - {: }3 g) U# X6 e. ^5 \( s
- Part *workPart(theSession->Parts()->Work());
& t+ g9 g) j) T( Q6 |1 N - 6 F/ v, `2 L& j) u7 O
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");/ a) Z7 J8 C: }: c3 Q
- Unit *length_units = workPart->UnitCollection()->GetBase("Length");
, j4 R |# L9 }6 R$ t) l - " j5 N& q- Z7 G- U% @, w# g7 w
- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));( T: O6 h$ H* z h
- std::vector<Face *> theFaces = theBody->GetFaces();
1 l" L6 z/ b1 D, D
) U: i7 r0 h% M8 T7 Z/ P! J- double bigArea = 0;
: r. l, }: u5 C9 n" p - Face *bigFace;
. L( n9 }& D! T) X1 Z! {+ H- {% h - std::vector<IParameterizedSurface *> theFace(1);
* Z0 t: Z# h* ]6 R6 _ - for (int ii = 0; ii < theFaces.size(); ii++)/ K; O \- l8 R; A9 ^ o& U
- {
" s, N/ } e. R* s0 Q) \- T - theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);1 Q/ n7 {' }" Z* ^8 F
- - D7 g2 c V" U! J1 N
- MeasureFaces *theMeasure = workPart->MeasureManager()->& b1 @7 ?9 T- J) y( u c
- NewFaceProperties(area_units, length_units, 0.999, theFace);
+ t8 Z4 G! y, U; e2 m
* h" C0 F1 E& G: c0 \4 ]! R. Z- if (theMeasure->Area() > bigArea)
7 K: }5 u+ V6 h( X# t6 ~) @ - {
5 B( M4 s0 }2 X% B6 H7 h - bigArea = theMeasure->Area();& V6 s9 _4 T$ r8 _3 N
- bigFace = theFaces[ii];& B8 Y) ?6 M! U4 ?4 Z# \; N
- }- g% \2 n- C) e
- }
; i, x" v2 |1 c E! N: d! q - - @" E" e8 s# v
- return bigFace->Tag();
l# |# }8 p4 I1 z4 K - }$ C% S+ A3 j# ~6 s8 L
复制代码 7 y+ L# c D7 Y" f
3 W6 n( X$ h6 i9 z2 s
6 u- V0 ?$ w) x }( k |
|