|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
: c4 a' ]$ P- [" W: w
# }( `1 d9 w+ C. y2 h- J4 m% O9 N
NX二次开发源码分享: NXOpen C++获取面的面积和周长
& B4 Z: L8 t* G" l% b% L' J, u
# \' R3 C0 I8 W* _ n) @4 X* O& o5 i) ?+ u0 p
7 L7 E p4 P9 E+ }3 a6 K3 g+ M
# n Y: t4 R: `8 Q9 h
' c% i r0 q. @5 E[mw_shl_code=cpp,true]double MyClass::MeasureFaceArea(TaggedObject* face_tag)
5 S$ {& S$ W8 Y* ^( I" y1 X1 y{
9 w( k1 ? |1 G char str[256];
! p# U) D" ]" N" I1 v ' h4 R4 p2 @/ _: N" m' O
Unit *unit1(dynamic_cast<Unit *>(workPart->UniTCollection()->FindObject("SquareMilliMeter")));9 E! q) y( S* ~; |1 j+ e
Unit *unit2(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
- A1 |. Y) e, C% P# e
- }" l6 l9 i. z7 c+ { //FaceCollector issue is fixed in NX9
8 A( X. s* U' A) { NXObject *nullNXObject(NULL);
4 X! |4 M, G& [2 P MeasureFaceBuilder *measureFaceBuilder1;; ^0 t Y+ U% a& x
measureFaceBuilder1 = workPart->MeasureManager()->CreateMeasureFaceBuilder(nullNXObject);
2 C" A! E) W! F1 B / \- y1 g6 X/ J' }
Face *face1 = dynamic_cast<Face *>(face_tag);: v- S- }. |9 _& r a
vector<Face *> faces1(1);2 y5 f7 ~5 B |. |, G7 u
faces1[0] = face1;3 D% O: i/ J- h) S( L
FaceDumbRule *faceDumbRule1;. f; h0 ^% J: o5 v* u
faceDumbRule1 = workPart->ScRuleFactory()->CreateRuleFaceDumb(faces1);: o/ G6 [3 v3 H0 x6 c0 L4 J! A
4 N1 O+ T7 N8 J9 u std::vector<SelectionIntentRule *> rules1(1);
- F$ U- E8 }9 s- F/ T9 \. m rules1[0] = faceDumbRule1;6 u; W0 g% v& c0 k
measureFaceBuilder1->FaceCollector()->ReplaceRules(rules1, false);* c; _' U6 Y6 w: u+ Z
NXOpen::NXObject *nxObjct1 = measureFaceBuilder1->Commit();: p0 g2 J# K4 X5 d3 i' p, N/ z
q4 d# O8 u. h3 L k+ t' W! R- a
NXOpen::ScCollector *scCollector1 = measureFaceBuilder1->FaceCollector();: l# w: K- }9 e2 q/ _
8 m* m- P5 ]1 B; w& D# [" i$ R! B- K MeasureFaces *measureFaces1;
" {# B# c$ V7 ?8 F: Y measureFaces1 = workPart->MeasureManager()->NewFaceProperties(unit1, unit2, 0.99, scCollector1);
& m. n# c7 A3 R- x$ B* h
e/ b. d. R+ a: _% T0 x double face_area = measureFaces1->Area();
" K0 |* h1 o: r, }/ [ sprintf_s(str, sizeof(str), "Selected Face Area: = %f",face_area);, n$ m4 h1 J# _+ Z
print(str);
0 J; a* t# b2 i8 m/ E# H0 g 3 k' _! T. U2 n# z
double face_perimeter = measureFaces1->Perimeter();
( F8 X6 P( {% h4 O F9 Q7 a sprintf_s(str, sizeof(str), "Selected Face Perimeter: = %f",face_perimeter);) q( R* Y/ d) q- c( F: ]
print(str);0 t* S' _. b: {# x* m
2 J } Y j9 t% [1 j9 k8 d( Y, B8 [ delete measureFaces1; ! E; h8 Z) U! v: T _. k
delete faceDumbRule1; `9 B2 E3 v. @! ?- P. X
measureFaceBuilder1->Destroy();
0 q9 I7 i3 X. I; [$ z return face_area;
2 v7 o+ B( K4 w5 T* m* V}, g/ v4 ]7 V |+ ]; @9 R" A5 Z
[/mw_shl_code]8 ?' F* o7 R% R1 N3 j2 u
|
|