|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
1 f( X9 G: `# N$ ?0 _1 @
NX二次开发源码分享:查找体中最大的面积" o o& p4 a) P2 F1 i
通过MeasureFaces 下的area方法可以得到面的面积进行遍历查询
/ \8 X; Q4 z1 W' v9 h$ E% _0 r) v4 ^; T8 M) K8 w, J$ w, \6 Z3 K
- x: `9 \7 e1 G& z" B) G: ^) e
- #include <NXOpen/Session.hxx>6 z* c* A8 f& W; C+ V
- #include <NXOpen/Part.hxx>
3 P! ~$ [) ~ _, {9 { - #include <NXOpen/ParTCollection.hxx>
9 ^7 l5 a2 v/ `8 Y - #include <NXOpen/MeasureManager.hxx>
/ E7 B2 ?, w% j' h - #include <NXOpen/MeasureFaces.hxx>, a3 K% p* [4 g* V; v9 `- O8 F
- #include <NXOpen/NXObject.hxx>8 N8 \2 \8 i! f; c2 O& C6 j
- #include <NXOpen/NXObjectManager.hxx>
+ x0 J0 s: J6 }& U4 I - #include <NXOpen/Body.hxx>* C* H0 x+ x' Q9 g6 v
- #include <NXOpen/Face.hxx>6 F1 R$ |3 L1 K/ ^- N- m
- #include <NXOpen/Unit.hxx>
2 m- h; i9 p8 M8 i - #include <NXOpen/UnitCollection.hxx>
2 j# |. |1 i( A) V - using namespace NXOpen;
7 C2 |$ e) ^9 E# p% @" x m
( z; v$ B, o& f }- static tag_t ask_largest_face_interop(tag_t body_tag): S! f, O `2 F
- {) h+ o/ w6 m& f8 _% H! u/ j
- Session *theSession = Session::GetSession();
" h7 K) u% q p( N# h - ; p: _, l3 p0 B7 t- [+ f& |, K
- Part *workPart(theSession->Parts()->Work());: L' ?) a3 c+ L y0 d% l. X
- & Z- x- b7 C% C! H
- Unit *area_units = workPart->UnitCollection()->GetBase("Area");
2 B/ o4 p/ U) p4 e4 ^. n+ Q - Unit *length_units = workPart->UnitCollection()->GetBase("Length");: k) c- P, T6 G( P
, y- p- d& L8 Z* Y- Body *theBody = dynamic_cast<Body *>(NXObjectManager::Get(body_tag));
1 t3 |: S7 q: ]" j' a - std::vector<Face *> theFaces = theBody->GetFaces();
, E8 @- [8 K6 S, ^9 i( D0 _ - 1 ~" K3 p& `5 O0 I( D9 J
- double bigArea = 0;
- D5 k. [$ ]0 s. i: M2 v2 n& l - Face *bigFace;
) F0 [, Q U P - std::vector<IParameterizedSurface *> theFace(1);
5 t; i Q0 S" j4 ~3 A" }' b - for (int ii = 0; ii < theFaces.size(); ii++)
k0 R* J- y6 `0 N5 s: ^. q4 x3 r - {- e7 w& a+ K. y/ B: b5 k
- theFace[0] = dynamic_cast<IParameterizedSurface *>(theFaces[ii]);. f; j5 M9 ~7 B
- + [3 ^/ k. ^6 F% k5 { `0 c
- MeasureFaces *theMeasure = workPart->MeasureManager()-># O t% ]' A! i
- NewFaceProperties(area_units, length_units, 0.999, theFace);! U! x4 Y! b6 s- z" i* u; l
* ^; P) Y% ]) l; {# S, h. t+ X/ l- if (theMeasure->Area() > bigArea)9 ?4 ]. L8 ~& q1 n/ `- {
- {/ T/ h' b6 K9 k0 C, D! N& w
- bigArea = theMeasure->Area();
: ^5 k1 t( ?+ @& q3 U5 ] - bigFace = theFaces[ii];$ c3 K( ]. x: v! g# _9 {9 T. d
- }
# ^0 q4 t% u0 R$ X4 f! X7 M- B) O - }
1 \4 Y6 u6 D- H# d$ E
2 i1 D' V% q# P2 c+ B- return bigFace->Tag();9 k( o7 R: }- a! v# n3 j
- }
( f* U* v& W; ]% R& S7 [
复制代码
7 L) m3 ?# M5 \$ W& T) n. R. o8 w
6 W- w. E8 _4 J/ S; y& O
& B* @6 r. M( v5 ]& @4 O& c' v |
|