查看: 6690|回复: 0

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

[复制链接]

2480

主题

1280

回帖

8万

积分

管理员

PLM之家站长

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

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

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

×
UG NX 二次开发源码分享:遍历所有的实体得到边面特征信息
4 }: x7 [5 C, Y5 U$ S 8 P) X3 ~+ r& @7 A- c6 u

5 J. J& l& d+ P2 q" o  theSession->ListingWindow()->Open();8 i' j. L5 Z5 i  K6 F
  theSession->ListingWindow()->WriteLine("Get information from all bodies\n");
% p; w. F6 I9 H     std::vector<Body *> bodies;% h% j( }! N; [! X/ c1 Z! U
  BodyCollection *bodyColl = workPart->Bodies();1 t, p6 V) o! I2 _! n; z1 A
  for(it = bodyColl->begin();it!=bodyColl->end();++it)3 v1 i$ P; z3 J  q: d) `! e; l
  {
5 h; F+ U" P- ]$ X   bodies.push_back(*it);; O8 }! p) B, d5 }
  }, u6 \! [! z0 w2 u" C. C/ X0 Q
  ss <<"Bodies count = " << bodies.size()<< "\n";
' T' b9 X" i& p# |' V   std::vector <Edge *> edges;* k7 g5 d6 }8 U
   std::vector <Edge *> totalEdges;
) p: K; d9 z7 G. b# ]: M  n. A   std::vector <Face *> faces;  N: N- D7 m) @2 I. e
   std::vector <Face *> totalfaces;! E$ p5 K7 x! y  _% [) ]
   std::vector <Features::Feature *> Features;
) F7 c5 n. ~, h. l! R   std::vector <Features::Feature *> totalFeature;
. g# C3 B5 u5 m5 D% i+ g! l8 J   Point3d vertex1,vertex2;
( V4 q/ y' V3 v" H. f8 {   for (unsigned int i = 0; i< bodies.size();++i)
: i; U/ W; H2 R# e  U, ~, n  ?   {
* l/ x9 i  N' T7 ?1 D: K/ w; S1 I    edges = bodies->GetEdges();4 m" d% |: m7 s; Z8 _
    faces = bodies->GetFaces();) l1 A+ x% _5 l4 F5 n+ r, K
    Features = bodies->GetFeatures();
5 g& [1 ]; c; f6 S     for(unsigned int j =0;j < edges.size(); j++)
: Z" K: g6 |. G+ z# X     {4 b( ^! ^$ b3 g- |. j/ n3 P1 O
     totalEdges.push_back(edges[j]);- c" K2 i: |) M6 L7 ^" o
     }
" d5 O/ I2 @; j9 o6 D     for(unsigned int j =0;j < faces.size(); j++)* f" K# u! b  o0 p4 j1 J$ J
     {% y4 d6 d: |& P& h0 d# |
     totalfaces.push_back(faces[j]);
1 p) B. p+ w' _5 k3 d$ [     }* m5 y( r. B, K/ M
      for(unsigned int j =0;j < Features.size(); j++)' g0 N$ Q6 {4 d. y' m# s& `* j6 j* _
     {& z& ?- k1 \1 c9 _* S4 p
     totalFeature.push_back(Features[j]);/ s% c) ?9 H  E' M, O9 X" c
     }
( Z6 s, o; K' e5 J+ E6 e' s      : ~0 s) [7 H! q3 [0 n
   }- l3 d& O: [0 v: i/ A
    ss <<"edges count = " << totalEdges.size()<< "\n";5 S& J6 y; ^2 t) c7 h! U! }
   for(unsigned int j =0;j < totalEdges.size(); j++)
5 ^8 }& J# o  h+ ]. u+ f     {   " J; ^* s% O. S# b
      totalEdges[j]->GetVertices(&vertex1,&vertex2);/ ?: G: }! ?/ o* {6 U/ ]- V
       ss <<"edges tag: " <<  totalEdges[j]->GetBody()->GetTag()<<"\t";
+ p% C& u  ~' K# r" E$ U  b       ss <<"edges vertex 1: "<<"("<<vertex1.X<<","<<vertex1.Y<<","<<vertex1.Z<<")"<<"\t";1 A, U5 t$ C8 e% X6 n+ u! a
       ss <<"edges vertex 2: "<<"("<<vertex2.X<<","<<vertex2.Y<<","<<vertex2.Z<<")"<<"\n";( X5 z$ l7 D$ C  i
     }" l8 `' R" X8 ?; Q6 E- l, G! R
   ss <<"faces count = " << totalfaces.size()<< "\n";3 C8 \' T2 ^* e; g" _
    for(unsigned int j =0;j < totalfaces.size(); j++)
* M. f" R6 q% K5 h, x4 z5 K6 ~# G    {  
8 w- I7 {/ n8 o' h     ss <<"Face tag: " << totalfaces[j]->Tag()<<"\t";( L4 n+ G1 D1 l& b- A; j" w
     ss <<"Face Type: " << totalfaces[j]->SolidFaceType()<<"\t";3 ]5 _% I9 \7 ^! A: ?1 v' E. U
     ss <<"Face Name: " <<totalfaces[j]->Name().GetUTF8Text()<<"\n";& Y: L; k; u' T- }1 ?/ a
    }8 b9 ?8 g; P  f; g! L7 S- G
   ss <<"Features count = " << totalFeature.size()<< "\n";
3 ~( q/ d$ J9 r     for(unsigned int j =0;j < totalFeature.size(); j++)
. b& l1 U7 _  V    {  # b2 b2 c. ^* |" ?2 s( ^  |
     ss <<"features tag : " << totalFeature[j]->Tag()<<"\t";
2 m9 o9 G( F4 G, z# D: o     ss <<"features Type: " << totalFeature[j]->FeatureType().GetUTF8Text()<<"\t";
6 ?4 C6 g; @: q5 W  k8 v     ss <<"features Name: " <<totalFeature[j]->GetFeatureName().GetUTF8Text()<<"\n";
7 Q% N3 q8 C, {( C" ?# K- c    }6 N5 J! A" M' a4 p6 U
  theSession->ListingWindow()->WriteLine(ss.str());. t- _4 _2 q, D

+ R1 w; _/ B& `- W7 Z. q& Y5 M0 y8 ~& U% |  B
查询结果如下:2 q7 O/ s' x0 i& ?$ J
1 z; u/ W2 d8 _9 d

' ]& ?# ^1 M9 o/ DGet information from all bodies3 i) E8 s" P  @, {$ X; x- ~
CYLINDERBodies count = 7
" E7 q. h. Q" M2 L9 i( wedges count = 22
: d3 G$ j" N! T6 M8 y1 W; j: ?edges tag: 41404 edges vertex 1: (100,0,0) edges vertex 2: (100,0,100)  q$ I7 F* _/ {7 r7 h* @
edges tag: 41404 edges vertex 1: (100,0,0) edges vertex 2: (100,100,0)
+ {. R5 m7 D2 g. J) iedges tag: 41404 edges vertex 1: (0,100,0) edges vertex 2: (0,100,100)
* p( j* C- H+ r& Yedges tag: 41404 edges vertex 1: (100,100,0) edges vertex 2: (0,100,0)7 ^2 R/ m) N  |! p
edges tag: 41404 edges vertex 1: (100,0,100) edges vertex 2: (0,0,100)- f2 [! A6 j* E% w' n
edges tag: 41404 edges vertex 1: (0,0,0) edges vertex 2: (100,0,0)3 @$ |, q2 @- B7 K' V6 x3 J) O
edges tag: 41404 edges vertex 1: (100,100,0) edges vertex 2: (100,100,100), x7 f# t+ N4 E
edges tag: 41404 edges vertex 1: (0,100,100) edges vertex 2: (100,100,100)+ _' V5 W0 ?7 l' Z! p2 n+ c
edges tag: 41404 edges vertex 1: (0,0,100) edges vertex 2: (0,100,100)
! a5 V8 B3 w- }edges tag: 41404 edges vertex 1: (100,100,100) edges vertex 2: (100,0,100)
7 X" k* s/ P" G( r5 {2 `3 iedges tag: 41404 edges vertex 1: (0,0,0) edges vertex 2: (0,0,100)" P' N) {5 @2 f' t! f2 G$ d8 ?
edges tag: 41404 edges vertex 1: (0,100,0) edges vertex 2: (0,0,0)
; q7 l+ ?. n/ _# d: y4 Y( F8 G4 Gedges tag: 40966 edges vertex 1: (50,0,100) edges vertex 2: (50,0,100)
9 H; o* m, X1 T" ^+ ?/ X6 T% fedges tag: 40966 edges vertex 1: (50,0,200) edges vertex 2: (50,0,200)
5 j+ V! B+ w" f- `$ Fedges tag: 40977 edges vertex 1: (50,0,200) edges vertex 2: (50,0,200)% H5 E9 ^6 S1 K$ V7 A
edges tag: 40977 edges vertex 1: (50,0,300) edges vertex 2: (50,0,300)
  j: W2 R6 l, j8 \* d! g; a; Yedges tag: 37824 edges vertex 1: (50,0,300) edges vertex 2: (50,0,300)5 f( q) P/ B3 w. }! F
edges tag: 37824 edges vertex 1: (50,0,400) edges vertex 2: (50,0,400)
1 E" \- Z: \3 o% x1 x) r% H/ medges tag: 41200 edges vertex 1: (50,0,400) edges vertex 2: (50,0,400); w* M/ o3 W9 _% \( W8 {
edges tag: 41200 edges vertex 1: (50,0,500) edges vertex 2: (50,0,500)5 C. L! I, R9 L  c
edges tag: 41357 edges vertex 1: (150,100,200) edges vertex 2: (150,100,200)0 S4 u0 H8 Q# K2 F' |% [( }
edges tag: 41357 edges vertex 1: (150,100,100) edges vertex 2: (150,100,100)
6 k0 P+ i# y  R) p' xfaces count = 22* z* ?* Y" [6 k* _0 V6 y
Face tag: 41407 Face Type: 4 Face Name: - O: |* b' I# U( T
Face tag: 41398 Face Type: 1 Face Name:
* }2 B& o8 }* f0 j- SFace tag: 41376 Face Type: 1 Face Name:
; \: \7 |. P6 ~1 P8 OFace tag: 41391 Face Type: 1 Face Name:
0 E6 |* T  X" r) W$ b" U! RFace tag: 41380 Face Type: 1 Face Name:
5 J% i" a2 ?% e% S8 NFace tag: 41396 Face Type: 1 Face Name:
2 n* G' O8 L# W: {, n" T. VFace tag: 41397 Face Type: 1 Face Name: , T* d, T' e! Y
Face tag: 40995 Face Type: 2 Face Name: 1 K6 ]# y& q: A, K1 x" E. G
Face tag: 40965 Face Type: 1 Face Name: , T/ @3 P% [, X3 P
Face tag: 40997 Face Type: 1 Face Name:
( Z% O5 N1 u! x) [% z1 `6 tFace tag: 41351 Face Type: 1 Face Name: - R2 i9 N* ~9 `. `# J% G) s  i9 n
Face tag: 41352 Face Type: 1 Face Name:
& `* H/ \; l9 G- B& S3 |Face tag: 41353 Face Type: 2 Face Name: ( I* f( ~6 X& `/ c/ |$ O/ K! i! F
Face tag: 38479 Face Type: 1 Face Name: . b5 }$ J# q% J) |# Y
Face tag: 38480 Face Type: 1 Face Name: ' X: U- A. H+ I* {0 i
Face tag: 38481 Face Type: 2 Face Name:
' @! d! I% M& aFace tag: 41207 Face Type: 1 Face Name:
. |# F0 l( K* Z/ gFace tag: 41203 Face Type: 1 Face Name: ; `  B8 x" Z5 W5 f2 G1 K
Face tag: 41158 Face Type: 2 Face Name: 3 g$ M3 C3 y! C, ]2 R
Face tag: 40987 Face Type: 2 Face Name:
% [' U' k  d7 m6 j  i6 Y  ?. PFace tag: 41010 Face Type: 1 Face Name:
6 R# a: G! {' E. G4 K3 mFace tag: 41001 Face Type: 1 Face Name: & V1 {3 R1 e3 q4 |7 [% z
Features count = 7  E/ x7 K8 f) Z3 u' I0 M
features tag : 41280 features Type: SPHERE features Name: Sphere(17)
& a* d$ l9 F3 S  K2 m$ Z6 Wfeatures tag : 41281 features Type: BLOCK features Name: Block(18)7 x8 S2 V5 w) e$ P
features tag : 41307 features Type: CYLINDER features Name: Cylinder(19)
& q. V" j9 d- |0 _1 bfeatures tag : 41314 features Type: CYLINDER features Name: Cylinder(20)7 E1 s. u1 `1 |# v6 |
features tag : 41322 features Type: CYLINDER features Name: Cylinder(21)* F) }. n# C8 o: q& d
features tag : 41330 features Type: CYLINDER features Name: Cylinder(22)
4 E' q# @3 M& A" h. n" kfeatures tag : 41338 features Type: CYLINDER features Name: Cylinder(23)
; Y: y# Q5 F8 _1 ~; b1 g9 k+ X3 x( M+ W$ ^
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

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

本版积分规则

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