|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
$ ~; P2 B" i$ d
& f+ ~$ w/ v8 ~$ H8 c$ c
NX二次开发源码分享: NXOpen C++获取面的面积和周长( d6 L4 O! O4 @7 y4 W* y8 |
- G) W: q x5 H+ t5 V9 V
# Q n: C; L5 D: M" q% f# [* T" ?' f" `
& U, d$ n+ Q' j/ T
1 o4 R4 j- y# M2 q# E9 m3 w% F
[mw_shl_code=cpp,true]double MyClass::MeasureFaceArea(TaggedObject* face_tag)
3 j9 k) K$ C+ B% ] T% z{
" ^& Y3 U8 i" C4 l( R char str[256];
9 Q& E1 [/ q1 d1 D$ g& I# {7 n7 A) w
0 M% f0 E: A/ u* M2 b6 a Unit *unit1(dynamic_cast<Unit *>(workPart->UniTCollection()->FindObject("SquareMilliMeter")));
0 b$ D9 e& u$ Y Unit *unit2(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));& |0 y+ e% K: m1 L6 }7 {" s
) l9 g# o6 I q. d //FaceCollector issue is fixed in NX9& U0 q8 v2 C ~* i. E6 o
NXObject *nullNXObject(NULL);0 P" X. F% z. k; t6 @( h
MeasureFaceBuilder *measureFaceBuilder1;( T" l8 L. q l" p. L, W3 s b
measureFaceBuilder1 = workPart->MeasureManager()->CreateMeasureFaceBuilder(nullNXObject); o- }2 i3 j* V: W$ O6 q8 x; {
6 j7 A3 m7 I {7 A) V
Face *face1 = dynamic_cast<Face *>(face_tag);
$ j3 S7 K7 K5 N6 X; [ L( X( @ vector<Face *> faces1(1);
, Y0 k! ]% _- E# r0 \ faces1[0] = face1;5 B8 |5 F, y% l4 o+ ^; j4 F
FaceDumbRule *faceDumbRule1;
" s$ {( U9 Q" M4 }' [ faceDumbRule1 = workPart->ScRuleFactory()->CreateRuleFaceDumb(faces1);
$ G% o" O3 b+ p' X% e
; K7 |5 h# `$ B2 H( V std::vector<SelectionIntentRule *> rules1(1);
2 x- G) }9 A+ h! l" F6 C rules1[0] = faceDumbRule1;
* o/ {$ @ U! N* d. O6 C" w6 c measureFaceBuilder1->FaceCollector()->ReplaceRules(rules1, false);: h' w9 \# m+ M' P' g) |, e
NXOpen::NXObject *nxObjct1 = measureFaceBuilder1->Commit();
: m1 |) w; z. n' N! {3 {9 x0 [! O9 c3 {' x
NXOpen::ScCollector *scCollector1 = measureFaceBuilder1->FaceCollector();
0 b: C0 A) i( Y) Y0 A6 [ Y+ ~* A3 W6 h; H+ U, h& L. ^
MeasureFaces *measureFaces1;0 S6 u N: b, V! ]1 q
measureFaces1 = workPart->MeasureManager()->NewFaceProperties(unit1, unit2, 0.99, scCollector1);. v/ Y7 }; E5 _6 `/ [
" P, P- ~" X( b
double face_area = measureFaces1->Area();
. ?- z$ H4 i, F sprintf_s(str, sizeof(str), "Selected Face Area: = %f",face_area);/ f" H q3 _7 h5 A1 w: u
print(str);
0 L, u8 c! z" c* N6 b- ?4 h8 S! u
1 Y+ k" w8 X) r0 L1 K" } double face_perimeter = measureFaces1->Perimeter();
4 u7 e6 `2 \; }3 a sprintf_s(str, sizeof(str), "Selected Face Perimeter: = %f",face_perimeter);
; C) e. p6 a4 S5 N0 x print(str);
2 r6 y- O8 l' `5 z4 [" q2 L
4 K8 _$ C2 G1 U1 y. W* E0 } delete measureFaces1; # F4 C8 S& a4 s7 [
delete faceDumbRule1; ]6 W8 |$ F" X
measureFaceBuilder1->Destroy();
5 Z8 c. U7 @/ y' U( G2 Q: Z2 R return face_area;
, u* q3 `1 A, W7 C}0 A( i5 }$ }9 z' Q
[/mw_shl_code]3 \+ q5 j4 h+ l7 u# N
|
|