查看: 6567|回复: 0

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

[复制链接]

6

主题

4

回帖

60

积分

管理员

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

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

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

×
UG NX 二次开发源码分享:遍历所有的实体得到边面特征信息
. W- ?6 r' s4 W * S" H, P0 n; x+ _% u2 x8 r7 \9 ?8 S

  I& c7 J+ A! Q+ K  theSession->ListingWindow()->Open();. g# S8 u1 `7 k- @+ B8 o+ B
  theSession->ListingWindow()->WriteLine("Get information from all bodies\n");
$ c0 K0 |6 w+ ]# P5 I     std::vector<Body *> bodies;
9 J- ^% F' h8 B$ ]8 \, v  BodyCollection *bodyColl = workPart->Bodies();" \* S& \' }6 A3 g  n2 Y1 y7 k
  for(it = bodyColl->begin();it!=bodyColl->end();++it)
* R1 x6 J7 e1 [  Z  {
0 P( l. m; T; r8 H2 i6 c   bodies.push_back(*it);
) C, \8 U3 T5 e# O7 z; A  }) d9 S) V4 F" v1 Y9 U9 `
  ss <<"Bodies count = " << bodies.size()<< "\n";- x, \) ^4 a  q8 p
   std::vector <Edge *> edges;
- W& a- [7 Z# ~+ G: ^/ J* Q   std::vector <Edge *> totalEdges;
- P3 ?: z' }8 T7 ~  B% g% v8 s   std::vector <Face *> faces;3 C2 b" O  l$ x* U" H3 ~
   std::vector <Face *> totalfaces;
/ x) j. |' w) z3 \. y  u7 ^) N   std::vector <Features::Feature *> Features;/ ?/ w& }3 ^( M) l4 A
   std::vector <Features::Feature *> totalFeature;, K6 _. o6 J  G/ M1 v: |
   Point3d vertex1,vertex2;. a  V' R' ~7 C( a& }% O; g
   for (unsigned int i = 0; i< bodies.size();++i)( f' o, I; I) D' f: }, N
   {) V1 ]" {( a8 i0 c& c+ M
    edges = bodies->GetEdges();
% _7 }9 s: g/ K" L0 ^* T- v7 n    faces = bodies->GetFaces();
$ @* q2 r8 y/ l% ?, L2 l    Features = bodies->GetFeatures();
, }( V# g" X2 L. P/ {& ^8 c     for(unsigned int j =0;j < edges.size(); j++)
$ U3 g8 @: K5 Z2 I. O0 d) O/ C( D) L     {& \. C% [1 S6 I" V& K( p8 |6 x% v3 d' \
     totalEdges.push_back(edges[j]);
3 Q0 b0 ^  y% ^" ^! y+ _* l     }  z$ l- X- y9 Z  p0 H5 @
     for(unsigned int j =0;j < faces.size(); j++)$ `! x. j: U2 C& U
     {8 l) y. M* `8 n
     totalfaces.push_back(faces[j]);
* N5 {) r9 p3 W8 w: w     }$ k6 H- r; V6 ^
      for(unsigned int j =0;j < Features.size(); j++)& d2 b! b) K2 B8 A' g3 d2 Z: B
     {: }! w7 R& S/ ?) K/ z
     totalFeature.push_back(Features[j]);4 j' ]2 `) m( g3 _5 g
     }
  W% N& Q6 Y9 _7 U8 c3 S* y7 `      
, h5 z$ q7 v5 S7 t, `5 Q+ A, q1 I$ L   }) O. p3 k4 a$ _8 k0 F7 x" x" f
    ss <<"edges count = " << totalEdges.size()<< "\n";
3 g/ F6 [' }& f& K2 y$ M. |2 M   for(unsigned int j =0;j < totalEdges.size(); j++)
/ m$ v, V2 o) B% O) k" I     {   + F3 X. _% D& h$ g+ W; i
      totalEdges[j]->GetVertices(&vertex1,&vertex2);9 B8 i% t8 u0 O! E& }0 x
       ss <<"edges tag: " <<  totalEdges[j]->GetBody()->GetTag()<<"\t";
( T' L: o9 l$ ?5 D# u- V$ S6 h8 M       ss <<"edges vertex 1: "<<"("<<vertex1.X<<","<<vertex1.Y<<","<<vertex1.Z<<")"<<"\t";
; l2 ]" |6 S1 q$ K5 j/ L       ss <<"edges vertex 2: "<<"("<<vertex2.X<<","<<vertex2.Y<<","<<vertex2.Z<<")"<<"\n";
- E  S3 A; ^' h' y+ g     }" e* Y/ J# \1 a( @# c
   ss <<"faces count = " << totalfaces.size()<< "\n";6 j6 ^5 a5 x+ f1 K" t! l
    for(unsigned int j =0;j < totalfaces.size(); j++)
6 |( P7 o9 g; I- e( ^$ L    {  ' K5 G/ H# X- W9 \/ l/ S6 t3 U
     ss <<"Face tag: " << totalfaces[j]->Tag()<<"\t";. ?% y. U/ U+ E, q( i0 H; l! C/ u
     ss <<"Face Type: " << totalfaces[j]->SolidFaceType()<<"\t";
0 ~* Y/ T+ t$ O/ u$ o     ss <<"Face Name: " <<totalfaces[j]->Name().GetUTF8Text()<<"\n";
1 k. I" s- B# M( a9 J0 [8 N    }
- \# L$ o1 j: T: |' f# C# b$ n+ j   ss <<"Features count = " << totalFeature.size()<< "\n";
1 Z. F, S- D/ m5 o     for(unsigned int j =0;j < totalFeature.size(); j++)
# g0 ]2 u5 H& q2 I    {  $ S  P3 T7 |) p2 o
     ss <<"features tag : " << totalFeature[j]->Tag()<<"\t";
* ?2 j5 K* A1 f     ss <<"features Type: " << totalFeature[j]->FeatureType().GetUTF8Text()<<"\t";0 |* F  h: V6 f8 s
     ss <<"features Name: " <<totalFeature[j]->GetFeatureName().GetUTF8Text()<<"\n";
, j( ~$ ]2 S3 y& r( B& j/ r  _    }
2 B, G. }- g/ |  theSession->ListingWindow()->WriteLine(ss.str());, R9 s% @6 j0 K
+ d0 W# j. }# _6 l
9 r" |. {; ]# n1 r6 k
查询结果如下:3 f# w0 q* I, {1 Y+ u5 Y

9 @9 H# h- z7 e% j  C0 m4 ?: |# _2 d4 |& o% ^; E6 Q3 s
Get information from all bodies
1 V3 l" w' {! dCYLINDERBodies count = 7: ~$ ?# S+ L' i& a7 K& Z" y. c
edges count = 22- ]: j* `0 n3 I% h4 G
edges tag: 41404 edges vertex 1: (100,0,0) edges vertex 2: (100,0,100)
' \" m. Z1 y- l  o" V$ d) `# Tedges tag: 41404 edges vertex 1: (100,0,0) edges vertex 2: (100,100,0), r, p8 d7 w6 Y. ]
edges tag: 41404 edges vertex 1: (0,100,0) edges vertex 2: (0,100,100)+ N+ {0 j  c# O7 T
edges tag: 41404 edges vertex 1: (100,100,0) edges vertex 2: (0,100,0)
: j2 Q4 n+ I% }6 d$ s' cedges tag: 41404 edges vertex 1: (100,0,100) edges vertex 2: (0,0,100)
! [0 ]& k5 |$ C: }+ nedges tag: 41404 edges vertex 1: (0,0,0) edges vertex 2: (100,0,0)
/ P7 ]# i1 `" w4 K- b2 m% O) Gedges tag: 41404 edges vertex 1: (100,100,0) edges vertex 2: (100,100,100)
1 F9 o; I0 p- a5 n0 zedges tag: 41404 edges vertex 1: (0,100,100) edges vertex 2: (100,100,100)
. [, a- q5 I0 q: {) ?edges tag: 41404 edges vertex 1: (0,0,100) edges vertex 2: (0,100,100)( ?( F8 [' F: `
edges tag: 41404 edges vertex 1: (100,100,100) edges vertex 2: (100,0,100)
3 r% N3 T: ?" e& `3 p! Y6 d* D0 J  [/ Ledges tag: 41404 edges vertex 1: (0,0,0) edges vertex 2: (0,0,100)
) ?5 g& {' e: C' t( t! `edges tag: 41404 edges vertex 1: (0,100,0) edges vertex 2: (0,0,0)) N: Z; `0 J2 n" Q) P
edges tag: 40966 edges vertex 1: (50,0,100) edges vertex 2: (50,0,100)
+ o4 m2 W; i4 Hedges tag: 40966 edges vertex 1: (50,0,200) edges vertex 2: (50,0,200)
. Y0 B/ h0 R' d. C- b- Kedges tag: 40977 edges vertex 1: (50,0,200) edges vertex 2: (50,0,200)+ p/ g" d6 \2 S4 {- w
edges tag: 40977 edges vertex 1: (50,0,300) edges vertex 2: (50,0,300), T% t& |! p9 w  p7 h5 g5 f7 E# [9 D
edges tag: 37824 edges vertex 1: (50,0,300) edges vertex 2: (50,0,300)' M$ v5 ]+ Y$ b2 |  N+ ~3 _
edges tag: 37824 edges vertex 1: (50,0,400) edges vertex 2: (50,0,400)
7 j0 j7 f: ]1 K3 a9 ]edges tag: 41200 edges vertex 1: (50,0,400) edges vertex 2: (50,0,400); G" O- c5 _; n$ \" p" ]* W
edges tag: 41200 edges vertex 1: (50,0,500) edges vertex 2: (50,0,500)1 C2 P. Z- j1 Z- D( I
edges tag: 41357 edges vertex 1: (150,100,200) edges vertex 2: (150,100,200)1 d0 V- q' Q# V8 @
edges tag: 41357 edges vertex 1: (150,100,100) edges vertex 2: (150,100,100)
* r/ x9 x7 a/ |' t: Efaces count = 22
- V6 f' ~# v9 R8 {5 fFace tag: 41407 Face Type: 4 Face Name: " V3 N  O1 E0 {
Face tag: 41398 Face Type: 1 Face Name:
: @5 I* U+ d- Z5 e0 \, a$ V) yFace tag: 41376 Face Type: 1 Face Name:
$ I$ i$ p/ }; @' r! SFace tag: 41391 Face Type: 1 Face Name: 6 [* f  y3 A- @
Face tag: 41380 Face Type: 1 Face Name:
  [0 P( N" E5 B! R: {+ m) [Face tag: 41396 Face Type: 1 Face Name: % m' l( K4 {) d
Face tag: 41397 Face Type: 1 Face Name: . j0 p" i# O0 h0 M0 k) u
Face tag: 40995 Face Type: 2 Face Name: & D9 m* p( p7 y& s2 _' i# D1 B# G
Face tag: 40965 Face Type: 1 Face Name:
& G( b* I! B$ {- C5 l  m( rFace tag: 40997 Face Type: 1 Face Name:
1 d0 d1 l+ a  k; C+ F+ {Face tag: 41351 Face Type: 1 Face Name:
- a9 |& Y* j; W' w4 }. LFace tag: 41352 Face Type: 1 Face Name: * y; W8 D/ S- l* {
Face tag: 41353 Face Type: 2 Face Name: 5 `: K! o/ p1 w2 `3 b- I' C: G: d
Face tag: 38479 Face Type: 1 Face Name:
0 t4 a5 g7 r8 B$ Q5 NFace tag: 38480 Face Type: 1 Face Name:
+ ^; @  X3 ?: W% ^2 T) QFace tag: 38481 Face Type: 2 Face Name: 4 |5 ]( n& ]* V" Q# r; n# }
Face tag: 41207 Face Type: 1 Face Name: 2 i* d0 ~5 r: X1 E
Face tag: 41203 Face Type: 1 Face Name:
) g0 G& q  [2 r# V) yFace tag: 41158 Face Type: 2 Face Name:
' z1 d8 ~9 I. s9 ~" KFace tag: 40987 Face Type: 2 Face Name:
5 M# ]3 ?% e1 _8 z- M* J" Y, d/ R* \Face tag: 41010 Face Type: 1 Face Name: $ O. |" e4 n6 G  {  h
Face tag: 41001 Face Type: 1 Face Name:
- Q1 ]0 U, }1 R1 k  qFeatures count = 7
' B. v& B* ^0 \# n0 \% H& sfeatures tag : 41280 features Type: SPHERE features Name: Sphere(17), c+ g% @9 [/ f- `
features tag : 41281 features Type: BLOCK features Name: Block(18)$ J% e8 [- Y0 x) H. z
features tag : 41307 features Type: CYLINDER features Name: Cylinder(19)
# W% ^; [5 w1 r& P; qfeatures tag : 41314 features Type: CYLINDER features Name: Cylinder(20)
% T, P* ~& |1 s/ z/ j( pfeatures tag : 41322 features Type: CYLINDER features Name: Cylinder(21)
% m" u' B7 u% I0 X1 K+ G, S0 lfeatures tag : 41330 features Type: CYLINDER features Name: Cylinder(22), T' K& W: N! K* Y
features tag : 41338 features Type: CYLINDER features Name: Cylinder(23)
3 H( z  q& d$ L/ @+ d2 K/ @2 m) v% G) o3 P
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

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