|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
( g7 y6 i* C0 @! H6 p! ?% n
2 G$ S N/ G* z$ B( w' Y, @ O! ^" jNX二次开发源码分享: NXOpen C++获取面的面积和周长4 ^: E, z) @; J
8 l* `) Q9 j2 f. m$ N! K1 A$ T& M% T+ |
( l: m# L( Y* C0 i( `/ B* Z
. c& \0 c Z3 ^" i
' v% u9 L- |. h' {4 Q# j+ W4 q) k+ G[mw_shl_code=cpp,true]double MyClass::MeasureFaceArea(TaggedObject* face_tag)
+ p( _9 c9 P# ~6 ]: K0 V" l- t{
( v' h& n" d/ B9 Q3 s2 |) D' g$ j char str[256];
" @3 @+ g0 l1 i " c; `/ _7 a: o8 q
Unit *unit1(dynamic_cast<Unit *>(workPart->UniTCollection()->FindObject("SquareMilliMeter")));
8 l' r' X4 u& ^, b Unit *unit2(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
; A' X; L. Y) p @3 @
5 M( @6 I' I9 C& Q0 | //FaceCollector issue is fixed in NX9
# \: _$ M( Y+ B" W% e NXObject *nullNXObject(NULL);
$ K: G$ ?( {$ _. x MeasureFaceBuilder *measureFaceBuilder1;) s) A9 R9 Z7 i$ u3 T3 ^7 X
measureFaceBuilder1 = workPart->MeasureManager()->CreateMeasureFaceBuilder(nullNXObject);" `' b" F+ N3 O9 {: c
8 g" y! _6 ~9 l5 l* x Face *face1 = dynamic_cast<Face *>(face_tag);+ s. [, d: s% \ R) b% W
vector<Face *> faces1(1);
& x. R( Z+ p6 C8 v' M faces1[0] = face1;
0 C F2 @- t% N& L$ @4 M$ _% u FaceDumbRule *faceDumbRule1;
* a: m9 ?4 F, o& c# d9 K* {2 ~; v3 s faceDumbRule1 = workPart->ScRuleFactory()->CreateRuleFaceDumb(faces1);& R0 V& X& c, Z! ]2 C! x0 K
$ Q0 g: l# K! U7 t& K: d
std::vector<SelectionIntentRule *> rules1(1);; x1 {: |: C) `; I+ X$ O0 ~3 G# v
rules1[0] = faceDumbRule1;
+ a1 @: d+ T* n! T3 _5 K- t7 i1 B measureFaceBuilder1->FaceCollector()->ReplaceRules(rules1, false);
: ^% R* z! J# |3 T6 x" o* g NXOpen::NXObject *nxObjct1 = measureFaceBuilder1->Commit();
, u& L/ |6 ^9 G( C3 `
# L# T* b1 l S7 Q9 j) ~" ] NXOpen::ScCollector *scCollector1 = measureFaceBuilder1->FaceCollector();+ i" M, ^, m2 J5 G& q) N
% `. b; m& B5 n
MeasureFaces *measureFaces1;
# @, a7 k& |9 ^7 ^ measureFaces1 = workPart->MeasureManager()->NewFaceProperties(unit1, unit2, 0.99, scCollector1);. y$ d. o2 D7 W. f
$ R$ E) @8 T9 Y# U6 P double face_area = measureFaces1->Area();
7 U3 [* [0 a. T Q4 O2 {# ` sprintf_s(str, sizeof(str), "Selected Face Area: = %f",face_area);) U' i: K2 K$ S/ H
print(str);; ], |0 ]$ ]# V0 p+ h6 [$ F
% U. t) \3 b C double face_perimeter = measureFaces1->Perimeter();9 n" p& ~0 V: T
sprintf_s(str, sizeof(str), "Selected Face Perimeter: = %f",face_perimeter);
5 {& Y- _9 Q0 Z8 ? print(str);2 E u! a0 [4 J" U/ P6 q* C: X
d5 |9 K0 q3 L3 O1 N delete measureFaces1;
/ X2 n& }- O- u+ T; z E0 S delete faceDumbRule1;0 z y9 @( @% J" [/ o& m, i
measureFaceBuilder1->Destroy();
2 W1 }. W* o5 S( _6 z return face_area;) f7 D" ?2 H' R4 ?. B! c/ R
}
8 m, }# b( g1 @[/mw_shl_code]
5 Z* i* r. \; t" B7 I |
|