PLM之家精品课程培训,联系电话:18301858168 QQ: 939801026

  • NX二次开培训

    NX二次开培训

    适合初级入门或想深入了解二次开发的工程师,本培训结合ufun,NXOpen C++,大量的实例及官方内部的开发技术对于老鸟也值得借鉴!.

    NX CAM二次开发培训报名 NX二次开发基础培训报名
  • PLM之家Catia CAA二次开发培训

    Catia二次开发培训

    Catia二次开发的市场大,这方面开发人才少,难度大。所以只要你掌握了开发,那么潜力巨大,随着时间的积累,你必将有所用武之地!

  • PLM之Teamcenter最佳学习方案

    Teamcenter培训

    用户应用基础培训,管理员基础培训,管理员高级培训,二次开发培训应有尽有,只要你感兴趣肯学习,专业多年经验大师级打造!

  • PLM之Tecnomatix制造领域培训

    Tecnomatix培训

    想了解制造领域数字化吗?想了解工厂,生产线设计吗?数字化双胞胎,工业4.0吗?我们的课程虚位以待!

PLM之家PLMHome-国产软件践行者

[二次开发源码] NX二次开发源码: 获取面的相邻面的信息

[复制链接]

2013-11-6 18:54:58 6249 0

admin 发表于 2013-11-6 18:54:58 |阅读模式

admin 楼主

2013-11-6 18:54:58

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

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

x
通过这个代码,可以获取选择面的相邻面的信息1 l5 T  C) T' _
NX open C++中使用了 选择对象 selectobject 函数,通过面获取边数据,通过边获取面,从而得到信息!  V# G. e7 h# ~% M  o4 ~

$ a7 I% ]7 t4 x; Y+ W
  1. #include <uf.h>
    $ ~! q( x+ t" y1 c' F- \
  2. #include <uf_ui.h>/ f( m+ Z$ v5 o* O
  3. #include <uf_object_types.h>) o" N/ Y$ j9 n+ a5 _
  4. 4 J1 z" T  }/ z0 v  R
  5. #include <NXOpen/Edge.hxx>
    , C5 K+ s9 J- j
  6. #include <NXOpen/Face.hxx>
    ! S2 a2 s2 `. y  b0 q4 O

  7. ; s% }2 _; D" T6 a1 c! z
  8. #include <NXOpen/ListingWindow.hxx>
    + P' o$ {9 B  B! t) E3 r& A" _$ o
  9. #include <NXOpen/NXException.hxx>
    6 E" H4 y; B' b6 W' `
  10. #include <NXOpen/NXMessageBox.hxx>% x# l& g0 C* p
  11. #include <NXOpen/NXObject.hxx>
    . A9 G9 q$ V9 ]3 Q* U! D
  12. #include <NXOpen/Part.hxx>
    ( X0 ?) N/ N& Z) ~; [, B5 \% C
  13. #include <NXOpen/ParTCollection.hxx>' M( T; J1 e5 N, b- r, h
  14. #include <NXOpen/SelectDisplayableObject.hxx>" n1 g$ i4 W8 J* ?
  15. #include <NXOpen/SelectDisplayableObjectList.hxx>% g6 j1 i. X. c* k2 h6 e) \
  16. #include <NXOpen/SelectObject.hxx>
    ! @4 W7 F  ~9 t  K9 n, ]
  17. #include <NXOpen/SelectObjectList.hxx>
    * }2 P- a+ B2 e7 r2 a
  18. #include <NXOpen/Selection.hxx>
    , D; p3 d+ h5 g: n! r( t" t! R/ g2 u
  19. #include <NXOpen/Session.hxx>; w5 g6 r: e0 I; b' F% ]2 z
  20. #include <NXOpen/UI.hxx>+ U7 l8 g* w2 T; w1 _) d0 K
  21. #include <NXOpen/View.hxx>- q  u& U/ ~$ o

  22. 9 ^6 v" @: I8 u0 M
  23. #include <iostream>2 w) W4 [4 p( {. i: R; |# L6 k# h
  24. #include <sstream>/ b! T5 [8 _: v$ N0 F6 J: z, N
  25. #include <list>0 Z1 j. p% ?' g8 g' P* T

  26. ) A5 j! \& E3 `; [! _
  27. using namespace NXOpen;
    2 w! a' F; B- R1 R6 y- h+ v, o. K
  28. using namespace NXOpen::Annotations;
    / E1 B% q8 q9 u* J" F4 G7 `) t& f4 w  s- K
  29. using namespace std;
    2 q) ]( a. b$ U

  30. - d; g0 b1 s4 @4 h2 S6 J& J! K% j! |# z
  31. class Gtac
    " Z. l$ s3 R9 A: [
  32. {2 I( U0 V9 C& T
  33.     // class members
    4 x, F3 a+ `3 x8 x( k
  34. public:8 O. f+ ]5 c) F- s
  35.     static Session *theSession;
    6 d, M# m  P0 M/ e6 G; l; x: Q
  36.     static UI *theUI;* X" F  ^. y* o1 u* C8 |1 j

  37. + R, t! x6 b* V- d( g5 |8 [
  38.     Gtac();
    ( f2 d% j! X; \" m3 D' V
  39.     ~Gtac();
    . j  k- i( u( f0 S* _4 I1 a
  40. 7 y, h1 v! ]- ]: G
  41.     void do_it();
    1 {' E  j/ L! S) r8 T

  42. 1 w: ^1 X0 ?! g/ Q7 K
  43. private:$ J) I# @* `. X/ r) o0 m
  44.     Part *workPart, *displayPart;7 O1 {8 L/ }0 O0 d/ I, I
  45.     Selection *sm;
    " t  o+ R$ T- P: T1 {
  46.     NXMessageBox *mb;
    % z+ B2 C; s8 v4 L1 ]
  47.     ListingWindow *lw;4 J: o+ h  A( s/ J

  48. ; [" z, I* s- Q5 o' w: x
  49.     Face* select_a_face();8 [& P8 R( @( J' @& k7 d
  50. 9 {! m2 T: Y  V4 A: S
  51. };. L8 {* B: x; E" d5 B" M+ I

  52. 8 _) `3 T+ _1 G
  53. //------------------------------------------------------------------------------
      m' k5 Q  Y8 b. a4 p
  54. // Initialize static variables
    5 [0 N! ~! w+ I
  55. //------------------------------------------------------------------------------% u* v2 i; l3 j" _# f& Q
  56. Session *(Gtac::theSession) = NULL;
    : g% [7 s! [1 }' g) I: \
  57. UI *(Gtac::theUI) = NULL;2 T1 b' [0 o: G' E3 k

  58. ) y! G( W; H* r6 D. h& k
  59. //------------------------------------------------------------------------------
    . J5 u/ U" j" Z! Y3 \& J. M
  60. // Declaration of global variables
    / U$ R4 R  P$ W! k9 r
  61. //------------------------------------------------------------------------------
    ( Y9 Z) D" }# W# K1 i
  62. Gtac *theGtac;
    ( X& S1 y! _  k/ v

  63. 9 q* `  r5 J% r% s/ Z8 l/ S2 i
  64. //------------------------------------------------------------------------------3 N- ]3 I& Y0 Y: d6 }
  65. // Constructor  E! j  N" l* |. T
  66. //------------------------------------------------------------------------------
    ; P2 X2 I4 a( C- B3 t
  67. Gtac::Gtac()
    $ l' z5 q7 t& V5 F, q0 Y
  68. {
    - _. k3 E+ K( E" L2 }8 ^
  69.     // Initialize the NX Open C++ API environment
    $ Z9 {7 P& F. Y2 ~. w7 `3 c( g
  70.     Gtac::theSession = NXOpen::Session::GetSession();
    ; @( b3 z% ^4 n$ D
  71.     Gtac::theUI = UI::GetUI();
    . w6 e0 k" ]2 q# l
  72. + N+ E1 ^( F9 h! p4 l
  73.     sm = theUI->SelectionManager();( h: V: P" i/ o9 |
  74.     mb = theUI->NXMessageBox();* {4 S% T- y) w+ Y" W+ V2 S$ p
  75.     lw = theSession->ListingWindow();
    " i3 X( q& V6 k! @6 M: m- w+ b, N

  76. & a/ V5 G/ z  p- t6 _) l( z
  77.     workPart = 0;
    ! h) o6 v0 P+ U1 ~; Z. i0 x
  78.     displayPart = 0;
    - E& U8 N; k+ c/ F( `
  79. }. I) }' D5 m' y) P7 T
  80. 3 x4 H9 z/ M, ~, b" W# D2 M
  81. //------------------------------------------------------------------------------
    $ i. G1 }- s6 l! r3 r$ P" l( S
  82. // Destructor
    " ^/ E+ N6 Y7 w+ a4 a2 D8 C" c
  83. //------------------------------------------------------------------------------$ l$ u7 F; `' S8 H: S7 Y
  84. Gtac::~Gtac(); k5 \5 n3 F& Y' X  a& y1 K- A
  85. {( ~+ K! U- A4 h, B: P( |0 p0 ]
  86. }6 D1 E4 f' `1 V" I4 x
  87. ! S& a- Q1 w$ l( z8 v! ^- T
  88. //------------------------------------------------------------------------------/ ?! L; Q* Z, ^4 Z" v+ S- @7 V
  89. // Selection
    8 D6 e0 d5 d$ i4 b8 u9 A! c  y
  90. //------------------------------------------------------------------------------5 }/ }) @1 ~  U: G9 R
  91. Face* Gtac::select_a_face()$ b2 q' m& |& `
  92. {% S; G& u* l5 a# q, g; V
  93.     // ask user to select a face. n' }6 h7 C& B) q- d% I
  94.     UI *ui = UI::GetUI();' U- `  S' ~. k' k% O$ O
  95.     Selection *sm = ui->SelectionManager();
    8 t. c: J* L) S1 l$ b8 G3 V
  96.     NXMessageBox *mb = ui->NXMessageBox(); // as of NX56 R8 J) f  l2 j, i; U
  97. 0 k( h% \1 H' U- ~- I
  98.     NXString message("Select Face:");9 T/ c: i$ L$ l5 r) ~/ k4 e0 i+ a
  99.     NXString title("Select Face");
    ( M  f3 P! G- u- E* B+ C, \; E+ a
  100.     Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;( x# P& D6 e+ y, ?& b9 z
  101.     Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
    9 _/ U9 a6 W: {2 s8 t$ W
  102.     bool include_features = 0;9 ~, o+ T& _2 O" W4 @
  103.     bool keep_highlighted = 0;
    ! c, e. U2 ~! m1 }

  104. ' {+ P/ E0 N6 {6 t
  105.     // Define the mask triple(s)9 K" W/ I- i' Y0 ^) v
  106.     std::vector<Selection::MaskTriple> mask(1);  \4 d$ W7 S! z, p
  107.     mask[0] = Selection::MaskTriple( UF_solid_type, 0, UF_UI_SEL_FEATURE_ANY_FACE  );
    ( S( E. u: k9 u3 @& q, a2 N
  108.     Point3d cursor;
    8 I* T2 g% f7 s# r. z
  109.     NXObject *object;
    3 Z& \* l( c: @5 \! }7 l

  110. 9 D7 g1 Z5 V, ]& ?$ B' n7 H
  111.     // Select objects using filter defined by mask triples
    " ?  B: I# R6 r6 C
  112.     Selection::Response res = sm->SelectObject(
    * M$ e+ C( C- l8 E
  113.         message, title, scope, action, include_features,
    " e, Q0 A  X! x' W
  114.             keep_highlighted, mask, &object, &cursor );2 G0 n$ x( t- E# v( h" |
  115. ( k% U1 F& ]2 g# ^9 r
  116.     if( res == Selection::ResponseObjectSelected )5 T8 P: E! }  Z; y9 h! w" I: M0 r
  117.     {
    : |9 u( Q, ?) D: d( o) ^
  118.         Face *aFace;
    * W. u3 B+ m" N  I
  119.         aFace = (Face *)(object);1 z3 f6 W! [% g
  120.         return aFace;
    1 }8 W1 ^% X. l
  121.     }
    6 F! g+ W  `% R  X

  122. , Z3 l) f; C) A/ c0 C& D
  123.     return 0;
    * q, p2 O0 y& p& S
  124. }9 ?+ a* z1 h2 O! o/ |
  125. + E+ V, G5 ^4 G1 B4 H% C0 g" d
  126. //------------------------------------------------------------------------------% v. [& E# ?/ _+ N9 _* p+ H/ z
  127. // start with our job...
    0 a) G* N6 x* m2 N
  128. //------------------------------------------------------------------------------5 ?3 @! q1 E5 C' u- E6 H" q$ i- E
  129. void Gtac::do_it()
    6 b* A% O2 {6 X- E
  130. {
    ) ?( b% ^" O, \5 Y
  131.     workPart = theSession->Parts()->Work();
      n# o8 p; Z# T+ S2 S
  132.     Part *displayPart = theSession->Parts()->Display();$ j% {2 v! ~, }$ ^5 j8 q/ b
  133.     stringstream out;
    , a! [+ Z  l" @* X/ M

  134. ( ]5 E5 v: c) z% d! C. n+ H
  135.     Face *theFace = 0;
    + |. i8 T- T) o8 s
  136.     std::list<Face*> myfaces;
    & B% [/ ?7 N* ]( f/ a
  137.    
    ) S5 g8 X% d" L4 ]
  138.     while( (theFace=select_a_face()) != 0 )0 C% ]# g3 |/ m1 t7 J9 W) X
  139.     {! q% A( c& e& o
  140.         if(! lw->IsOpen() ) lw->Open();
    " n! P% `, X8 A' t
  141. : `, V6 d! S" C  Z
  142.         out << "Selected Object: " << theFace->Tag() << endl;. y$ J$ ?+ l  D6 v  i
  143.         lw->WriteLine(out.str().c_str());
    0 G: h4 N! ^' T0 l, D2 O

  144. 1 ^' U  D! R8 V- q+ a
  145.         std::vector<Edge*> edges = theFace->GetEdges();6 C4 X) t' m2 c& h
  146.         out.str(""); out.clear();
    - j; U! U7 S( T3 Q8 Y3 I) x
  147.         out << " Number of edges: " << edges.size() << endl;
    1 a" s  p8 n1 g' ~; M9 B1 e
  148.         lw->WriteLine(out.str().c_str());0 b$ {5 l* y/ s- N- T) s' U
  149. ( ?  L$ k/ d2 b4 R) q
  150.         for( int ii = 0; ii < edges.size(); ii++)
    ; M; w  o# u7 _" E% E
  151.         {+ W" L! V( u  p9 `( S# Z( b
  152.             out.str(""); out.clear();
    $ P5 w( s/ T% _3 s1 d( A  p; K
  153.             out << " Edge: " << edges[ii]->Tag() << endl;5 Z7 i0 A6 h, T" T  _
  154.             lw->WriteLine(out.str().c_str());! |" O/ o. f. t6 u5 b

  155. + a! ?( }) V1 {3 M. q. u% l
  156.             std::vector< NXOpen::Face * > adj_faces = edges[ii]->GetFaces();1 h2 G- _. y4 v& E) s  }  G6 ?' [
  157.             out.str(""); out.clear();, _1 v  {" W+ A! ]* `2 Y" n% N
  158.             out << " Number of adjacent faces: " << adj_faces.size() << endl;% z0 ]( l6 d- V7 _
  159.             lw->WriteLine(out.str().c_str());' W7 t: v. V; ]
  160. . S2 \. |. W3 [
  161.             for( int jj = 0; jj < adj_faces.size(); jj++)! P$ M8 q0 K6 y! ?8 i
  162.             {  U- v8 E" {% |
  163.                 out.str(""); out.clear();. M( R9 _' P, D  K( v5 z5 a* P
  164.                 out << " Adjacent face: " << adj_faces[jj]->Tag() << endl;. k7 `" ~1 }% V( y
  165.                 lw->WriteLine(out.str().c_str());+ N  w: f* j/ r6 O3 z8 K4 a7 P" u
  166. 8 V/ ?+ p# v2 g1 j2 j2 [
  167.                 myfaces.push_back(adj_faces[jj]);+ x, D5 g7 s6 ?+ K
  168. 9 Y+ m3 j' U; R' c4 i1 B
  169.             } // jj3 J: N" e1 y3 K

  170. ' @5 |; j; a+ I3 _6 x3 j1 i( z
  171.         } // ii
      E. i. T7 H7 J3 H+ \1 J

  172. ) C* g2 Q' w3 l
  173.         myfaces.unique();
    3 i& n, G8 k# x8 P. z
  174.         for (list<Face*>::iterator it=myfaces.begin(); it!=myfaces.end(); ++it)
    : U+ B0 {2 V1 \3 b# T9 B" W
  175.         {, w7 C0 o  c3 y  \
  176.             (*it)->Highlight();, H7 k0 I  \& i  U( l% G4 D" n
  177.         }
    4 R, s. e2 p3 [& Q) T4 U: W5 T
  178.         Gtac::theUI->NXMessageBox()->Show("Adjacent Faces", NXOpen::NXMessageBox::DialogTypeInformation, "Confirm");
    4 ^# |9 e3 z9 H" i7 d& ]- J
  179.         for (list<Face*>::iterator it=myfaces.begin(); it!=myfaces.end(); ++it)! F/ y) o+ d' {4 _6 a, V
  180.         {! {$ m/ i, o# b, F
  181.             (*it)->Unhighlight();' }9 C" F! h, m# _
  182.         }
    0 a. {4 Y" F4 E6 N/ O, ?
  183.         myfaces.clear();8 Y3 S1 H  k- f1 q' U0 q

  184. 9 G& C8 l2 y0 ^) J7 T

  185. # i8 d1 N8 f) v2 c7 q& p
  186.     } // while
    7 n' Z5 w" E' J. l! Z: E
  187. }
    * _4 W0 x. ]( ~! g( `: n) N

  188. ) g( g- W" s+ x$ H  a
  189. //------------------------------------------------------------------------------
    # l  v$ U3 [4 y6 {
  190. // Entry point for our unmanaged internal C++ program
    7 Z( D0 a0 J' `1 m/ ?! Y  E
  191. //------------------------------------------------------------------------------7 u$ r% F/ F& G# ^  F, h1 c# A
  192. extern DllExport void ufusr( char *parm, int *returnCode, int rlen )3 x) m* R6 I  n- o: |
  193. {
    ! S( p+ V0 Y% t9 D# L3 l. C
  194.     try
    , u/ U, |& w) m" o
  195.     {! c: M) B+ ]" T' ?2 y
  196.         theGtac = new Gtac();$ O  B! F+ o6 F9 u) j9 j% z
  197.         theGtac->do_it();2 @, O2 v4 k% `
  198.         delete theGtac;+ H4 P9 \4 ~+ c, `$ ]+ S, w9 X
  199.     }- J" x8 f$ y$ c6 [
  200.     catch (const NXOpen::NXException& ex)1 k6 b# J- T7 |# t% F
  201.     {/ N  {3 G. Q- {& j6 g/ @: s
  202.         // ---- Enter your exception handling code here -----
    / ^+ F  k  Z0 |& R  _0 I8 S7 t9 u
  203.         Gtac::theUI->NXMessageBox()->Show("CaUGht Error", NXOpen::NXMessageBox::DialogTypeError, ex.Message());9 R* P  a/ J9 V+ V! w
  204.     }
    1 H1 r4 Z- D  I# ]4 e4 `1 }
  205. }+ p  J& H# ^, R% Z% ^  q/ K

  206. , `  S6 q+ N2 A

  207. 7 a+ W( d8 E& T# o
  208. //------------------------------------------------------------------------------, R! P# _( `! H0 ]: }6 A9 L9 |
  209. // Unload Handler/ {5 ?, T8 _" G; o+ P+ b1 a
  210. //------------------------------------------------------------------------------
    7 g" c, ?+ {8 }, j; B
  211. extern "C" DllExport int ufusr_ask_unload()
    & u$ g+ l% p: G4 x& j/ B( `
  212. {& M5 T9 X& \/ i* @4 o+ w' c. U
  213. return (int)NXOpen::Session::LibraryUnloadOptionImmediately;
    0 k4 T0 m% _8 J5 _1 b& j
  214. }1 d& T" C7 c; H2 \
  215. ' `8 l0 z6 E( h0 C, s
复制代码
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了