查看: 6602|回复: 0

[二次开发源码] UG NX 二次开发源码分享:遍历所有的实体得到边面特征信息

[复制链接]

2477

主题

1280

回帖

60

积分

管理员

PLM之家站长

积分
60
QQ
发表于 2013-11-4 16:53:51 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

×
UG NX 二次开发源码分享:遍历所有的实体得到边面特征信息
7 S6 [; }& T7 q3 t. c+ I" d ' x6 d7 w; A( X1 i( M3 Q9 Q1 a

- \% [" M) R# z7 D4 {  theSession->ListingWindow()->Open();1 U; a( y, f# {9 P. E1 }
  theSession->ListingWindow()->WriteLine("Get information from all bodies\n");
/ g, |& J: j9 Z% I     std::vector<Body *> bodies;6 P# }$ g+ x9 l; M
  BodyCollection *bodyColl = workPart->Bodies();
7 w  u5 s, [4 u4 Y' k7 v! v  for(it = bodyColl->begin();it!=bodyColl->end();++it)
. M/ \+ P: R( v  {
/ L' D- T3 z1 C8 B   bodies.push_back(*it);
2 d1 Y' X7 F( Q8 j% e  }& Q) d4 F# ]* [5 x/ t- I: j
  ss <<"Bodies count = " << bodies.size()<< "\n";6 P7 ]6 K) U/ L+ c( o; U6 V
   std::vector <Edge *> edges;# l+ z7 a% o( H  g; w+ R( N
   std::vector <Edge *> totalEdges;
- c9 u5 N2 L1 `7 K; b% N6 K   std::vector <Face *> faces;
/ n+ u4 f7 d$ j0 w+ m1 \   std::vector <Face *> totalfaces;+ C5 F( d% b' Z, v1 L" o& w% R
   std::vector <Features::Feature *> Features;
4 K3 t' G& |6 _   std::vector <Features::Feature *> totalFeature;# m1 m) u0 b2 Y1 i0 [* Z
   Point3d vertex1,vertex2;4 q( C& t/ Z5 G1 W+ `: B
   for (unsigned int i = 0; i< bodies.size();++i)
- u+ }$ I* D% B4 Y- M  s7 a# A   {
" L  ^' L& F4 N    edges = bodies->GetEdges();5 ]! K9 v8 d7 F* O$ f8 P# l. B* u
    faces = bodies->GetFaces();' ~6 h, l: C% f2 Z. a
    Features = bodies->GetFeatures();1 ]  C; J) c. P. ]
     for(unsigned int j =0;j < edges.size(); j++)2 ?; L: D# V2 [5 t4 d5 x5 f
     {
7 q6 K. ?8 v: Z) ~( z5 \/ [+ g     totalEdges.push_back(edges[j]);$ L' q/ P8 t' L' I+ _
     }
! T" ~: w( K2 K     for(unsigned int j =0;j < faces.size(); j++)
8 G2 i0 e0 V0 f, ~" W0 A     {
) R( ^. K" i2 y7 a: C1 ~     totalfaces.push_back(faces[j]);
6 `. W2 g' `" R# J- z     }2 U. \9 L& |6 s; }
      for(unsigned int j =0;j < Features.size(); j++). m* @& N5 T( \- S+ i, |  q; G
     {; R/ g9 \+ u1 p$ r0 |  ^7 m
     totalFeature.push_back(Features[j]);9 v- P% ?: A$ _: v" A% R
     }
& w/ P8 f) D# ^      $ l7 G; \, b4 S0 u- d- V
   }; J" f! T0 X: Y) d! u
    ss <<"edges count = " << totalEdges.size()<< "\n";- p  N  W& M5 }0 u3 i) d, t
   for(unsigned int j =0;j < totalEdges.size(); j++)8 H7 o( D% k8 V7 c0 F! h# K8 g
     {   4 [2 x( }: M: N+ l
      totalEdges[j]->GetVertices(&vertex1,&vertex2);
+ k4 ]( }) L7 [       ss <<"edges tag: " <<  totalEdges[j]->GetBody()->GetTag()<<"\t";. Y. w. A2 m% W  K& S% R
       ss <<"edges vertex 1: "<<"("<<vertex1.X<<","<<vertex1.Y<<","<<vertex1.Z<<")"<<"\t";  Q/ R) T6 G/ D+ ~4 O/ d* n, s  s
       ss <<"edges vertex 2: "<<"("<<vertex2.X<<","<<vertex2.Y<<","<<vertex2.Z<<")"<<"\n";% J1 P) A* s. m3 |- @6 Z1 l& b
     }
; q: H- d2 R% g6 M: [" g# J   ss <<"faces count = " << totalfaces.size()<< "\n";
1 ]! L+ [4 d5 s4 |    for(unsigned int j =0;j < totalfaces.size(); j++)$ V& v; ?, I* P1 l. ~0 p1 F
    {  
" T% k' o! q; \" N; S6 r/ C     ss <<"Face tag: " << totalfaces[j]->Tag()<<"\t";
4 D/ R% H3 {) z/ g) V! W     ss <<"Face Type: " << totalfaces[j]->SolidFaceType()<<"\t";
7 u, x+ R7 z7 I7 S) T7 M     ss <<"Face Name: " <<totalfaces[j]->Name().GetUTF8Text()<<"\n";
) A' _9 a" v4 @6 t) G" E1 g$ X    }
# q0 t9 f& l2 e* U' v' l0 J   ss <<"Features count = " << totalFeature.size()<< "\n";
/ N7 i; r) v1 E' P0 c6 n% A. Z     for(unsigned int j =0;j < totalFeature.size(); j++)
, d( ?7 v# V5 y% _$ s- e$ V8 |# }    {  4 b" R6 _/ v/ z% V6 @) a" Z: ^% E
     ss <<"features tag : " << totalFeature[j]->Tag()<<"\t";7 K6 |) P/ N2 J1 g
     ss <<"features Type: " << totalFeature[j]->FeatureType().GetUTF8Text()<<"\t";
4 h  h4 I& a# y& f4 l& }2 Z     ss <<"features Name: " <<totalFeature[j]->GetFeatureName().GetUTF8Text()<<"\n";
/ T& {7 }. D( N5 u+ U$ i    }: v& C4 Q8 x3 w+ [4 h, x8 s4 P( }
  theSession->ListingWindow()->WriteLine(ss.str());) h+ A6 w- |: ?' X
; _5 b% D) D0 l
% X0 Q( b+ x- a& h! r9 ^4 }
查询结果如下:
. W" a8 c$ _7 W' X$ a3 i) @6 w0 A: g" Y
/ S& N" H# T# [8 a4 _4 T2 s
Get information from all bodies  [& u. H' |; K( a
CYLINDERBodies count = 7$ G7 d7 e2 n3 T! g5 M, x4 p
edges count = 222 j8 s8 x3 I! a9 m
edges tag: 41404 edges vertex 1: (100,0,0) edges vertex 2: (100,0,100)0 |/ }) F2 k4 Y' f, `. C- b3 b
edges tag: 41404 edges vertex 1: (100,0,0) edges vertex 2: (100,100,0)
9 V0 A2 ]9 A; s0 g; S! Zedges tag: 41404 edges vertex 1: (0,100,0) edges vertex 2: (0,100,100)
4 N3 Z: p! `- d" F8 m" Q! cedges tag: 41404 edges vertex 1: (100,100,0) edges vertex 2: (0,100,0): J5 H4 q- n$ C6 C
edges tag: 41404 edges vertex 1: (100,0,100) edges vertex 2: (0,0,100)
2 Q' }0 y7 Y* Q7 @/ {edges tag: 41404 edges vertex 1: (0,0,0) edges vertex 2: (100,0,0)& j2 E+ ]8 H7 C; O5 Q
edges tag: 41404 edges vertex 1: (100,100,0) edges vertex 2: (100,100,100)5 u& ]. D- X9 z* i: a6 y! [$ m
edges tag: 41404 edges vertex 1: (0,100,100) edges vertex 2: (100,100,100)
: c6 t# O7 x. J% `% v  Medges tag: 41404 edges vertex 1: (0,0,100) edges vertex 2: (0,100,100)
; T  ]8 V8 Z7 B9 n. ^5 g; J; h( Z( Zedges tag: 41404 edges vertex 1: (100,100,100) edges vertex 2: (100,0,100)
- l4 p9 a/ H2 l/ P* Redges tag: 41404 edges vertex 1: (0,0,0) edges vertex 2: (0,0,100)# e# M5 ^# T" y5 [7 h& `
edges tag: 41404 edges vertex 1: (0,100,0) edges vertex 2: (0,0,0)- o0 T5 N  ^: ~; [6 \$ i
edges tag: 40966 edges vertex 1: (50,0,100) edges vertex 2: (50,0,100)
' Z/ @3 y0 ?# H2 ~" l  S$ v- I3 Vedges tag: 40966 edges vertex 1: (50,0,200) edges vertex 2: (50,0,200)
0 r# Y9 e, a) o, W' ~. D7 ?edges tag: 40977 edges vertex 1: (50,0,200) edges vertex 2: (50,0,200)
2 g0 b7 }3 f4 i6 w2 S( z4 @  n0 gedges tag: 40977 edges vertex 1: (50,0,300) edges vertex 2: (50,0,300)
' q0 Z/ _/ S. \1 Eedges tag: 37824 edges vertex 1: (50,0,300) edges vertex 2: (50,0,300)  V" h5 A0 j+ y
edges tag: 37824 edges vertex 1: (50,0,400) edges vertex 2: (50,0,400)" W1 r5 ^: c* @2 _3 L
edges tag: 41200 edges vertex 1: (50,0,400) edges vertex 2: (50,0,400)
( V# G0 t6 n1 {6 j. L3 I. p( Wedges tag: 41200 edges vertex 1: (50,0,500) edges vertex 2: (50,0,500). I  d+ M" w* h! i, h0 F
edges tag: 41357 edges vertex 1: (150,100,200) edges vertex 2: (150,100,200)/ k3 f! }/ X- T. T) G
edges tag: 41357 edges vertex 1: (150,100,100) edges vertex 2: (150,100,100)
( \" \5 [; e' tfaces count = 220 ?5 a, A  w  {+ C3 Y* z- Q# j
Face tag: 41407 Face Type: 4 Face Name: ' m+ D) k* `1 ~- l
Face tag: 41398 Face Type: 1 Face Name:
" q- H: J: A- E8 c2 a" M3 e! rFace tag: 41376 Face Type: 1 Face Name:
; O) C0 ~! H- EFace tag: 41391 Face Type: 1 Face Name: . u5 [, C; @) R. }
Face tag: 41380 Face Type: 1 Face Name: ; C8 c& G8 z6 H0 j
Face tag: 41396 Face Type: 1 Face Name: 5 u( v! ]8 M& b4 b; A/ C* x
Face tag: 41397 Face Type: 1 Face Name: & W/ }- ^0 ~3 M, v) N1 W+ {: ?
Face tag: 40995 Face Type: 2 Face Name:
( P; e8 t7 q% u- X2 A+ IFace tag: 40965 Face Type: 1 Face Name:
( R/ T7 l  g) J( @Face tag: 40997 Face Type: 1 Face Name: 5 V/ v; f2 t3 Y! E, _7 Y
Face tag: 41351 Face Type: 1 Face Name: 8 v" x& |6 v3 W9 U3 U) U
Face tag: 41352 Face Type: 1 Face Name:
; L2 u5 h! X% }: K# T$ tFace tag: 41353 Face Type: 2 Face Name: ; _) |" V! T) p- e( p  [
Face tag: 38479 Face Type: 1 Face Name: 3 ^  }7 C6 X& L+ q3 S" O4 i
Face tag: 38480 Face Type: 1 Face Name: # b+ p( I  R' `( l7 t
Face tag: 38481 Face Type: 2 Face Name:
0 }  B5 l4 C/ vFace tag: 41207 Face Type: 1 Face Name:
2 g- B& s6 W$ u* cFace tag: 41203 Face Type: 1 Face Name: . g6 L' t8 S9 {6 u8 f+ [
Face tag: 41158 Face Type: 2 Face Name:
7 x/ i' [* P1 cFace tag: 40987 Face Type: 2 Face Name: ; J6 w! R7 p6 A( ]
Face tag: 41010 Face Type: 1 Face Name:
) A( |. W" F$ IFace tag: 41001 Face Type: 1 Face Name: " ~9 f- Z( W' X0 D6 B
Features count = 7/ |- `7 {1 V0 _- a
features tag : 41280 features Type: SPHERE features Name: Sphere(17)
+ T, Q  D7 B% Dfeatures tag : 41281 features Type: BLOCK features Name: Block(18)
7 j1 u2 l0 U/ }0 I& [! Y0 Tfeatures tag : 41307 features Type: CYLINDER features Name: Cylinder(19)
: a* K+ E$ s2 l8 F1 h9 jfeatures tag : 41314 features Type: CYLINDER features Name: Cylinder(20)
7 e; v: E0 |  j( s+ P6 Ofeatures tag : 41322 features Type: CYLINDER features Name: Cylinder(21)* S0 t+ h) H! ?9 G! k6 _
features tag : 41330 features Type: CYLINDER features Name: Cylinder(22)
: Q& b' d# _/ vfeatures tag : 41338 features Type: CYLINDER features Name: Cylinder(23)
- [% D7 p" ?+ G$ n* W* k1 V, X
4 ]$ a. i. c% }- ]$ ~
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部