|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
}: @* Y @3 N5 p
7 A1 R; x0 N/ H: K* _$ xNX二次开发源码分享: NXOpen C++获取面的面积和周长
3 E1 L9 z- U# i" A% `) e B% f
5 g# h; \4 K$ d0 K1 j9 {: C; S$ u
+ B, M, ]* b& E Q# w6 C6 w( k; n" Y
* ^+ \ M! b6 x9 U0 R) x0 {1 k( m, k* Y
" K, m5 V' ]7 S! M& v2 H4 m[mw_shl_code=cpp,true]double MyClass::MeasureFaceArea(TaggedObject* face_tag)
2 J6 {1 Z! ]+ B, O{
9 [% o0 a( r# G7 F2 Q3 b( u char str[256];8 y, N& A* ]' ^) P3 I8 G. x: i% p! m
8 V+ S: I5 y% h) D! x- L( W U# h
Unit *unit1(dynamic_cast<Unit *>(workPart->UniTCollection()->FindObject("SquareMilliMeter")));2 K3 \, x1 v0 \: K* v! {% B
Unit *unit2(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
& v& U" n% @2 \: l% e) Z+ W- g3 S1 _# @" S( Z' {1 r7 f
//FaceCollector issue is fixed in NX9
6 ~+ @0 j2 N) T+ [% | NXObject *nullNXObject(NULL);
, t9 o& |. y1 s' @" @" U MeasureFaceBuilder *measureFaceBuilder1;! R* Q7 l( }9 U5 I
measureFaceBuilder1 = workPart->MeasureManager()->CreateMeasureFaceBuilder(nullNXObject);
2 U5 h# c0 x6 p9 v
- m9 u* G/ G! t4 c5 T3 x8 Z) K Face *face1 = dynamic_cast<Face *>(face_tag);9 ^. s( O" \6 S) z3 T
vector<Face *> faces1(1);# N/ S) K0 t; ], [
faces1[0] = face1;
7 Q1 G) q2 O6 I5 e/ M2 o& U: o/ K/ d FaceDumbRule *faceDumbRule1;
% b, e% E/ i7 U6 x6 I! u. w faceDumbRule1 = workPart->ScRuleFactory()->CreateRuleFaceDumb(faces1);; u0 }9 w# X3 T, i& z6 I) t
6 i6 C1 k! p8 z4 b/ X. U; o
std::vector<SelectionIntentRule *> rules1(1);
5 Z/ q4 I3 z! W# t7 K rules1[0] = faceDumbRule1;
& U+ F. i) M: Y$ K. s, M measureFaceBuilder1->FaceCollector()->ReplaceRules(rules1, false);$ x3 j. w. t5 L1 ~! z
NXOpen::NXObject *nxObjct1 = measureFaceBuilder1->Commit();# h/ N+ u1 \8 a% }' R: L% C
& W! n& \" f) c% P6 | NXOpen::ScCollector *scCollector1 = measureFaceBuilder1->FaceCollector();% B0 M' q8 N2 z* g5 B
/ ~5 h1 M9 }) F
MeasureFaces *measureFaces1;* K. b4 i& H8 g* _) U! T- A- R
measureFaces1 = workPart->MeasureManager()->NewFaceProperties(unit1, unit2, 0.99, scCollector1);
0 r. b' p3 g$ {# u" V, X. B# \( S- r% G( v% Q+ D( S# c9 m F
double face_area = measureFaces1->Area();. X4 E; i9 D& J$ s! I
sprintf_s(str, sizeof(str), "Selected Face Area: = %f",face_area);2 g; M4 z B! q2 d
print(str);
( B9 l/ i" w! ? - D% l+ {; s5 \) O' T. O( @6 T) y
double face_perimeter = measureFaces1->Perimeter(); I0 ]( g+ Y. H- Z7 `; m
sprintf_s(str, sizeof(str), "Selected Face Perimeter: = %f",face_perimeter);6 d3 q, A o; X( ?1 k
print(str);
8 Z$ V. [; e! l ^4 F, O- d' E, q3 D! O) ~* g/ N8 o! j" ?
delete measureFaces1; # m+ n4 F3 `0 E. d
delete faceDumbRule1;
; c+ g0 A7 Z# E! G- t: g# g! D B7 e measureFaceBuilder1->Destroy();
$ G, o. s, W0 p& O return face_area;! b" p: E! n6 I Q' P
}
. i P, p, ^, ^( }[/mw_shl_code]* e% I$ S3 Y4 [) O& g0 v" |
|
|