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

[二次开发源码] NX二次开发源码:使用NX Open C++选取注释

[复制链接]

2013-10-30 14:00:47 4520 0

admin 发表于 2013-10-30 14:00:47 |阅读模式

admin 楼主

2013-10-30 14:00:47

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

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

x
NX二次开发源码:使用NX Open C++选取注释  K- t, `0 Y) w* B3 j* s5 `+ b
  1. #include <uf.h>% K$ o- {$ Z+ `3 R7 x% J
  2. #include <uf_object_types.h>$ _4 f8 w% |: w& _

  3. - E* U6 g, T/ B$ Y! c$ h' c
  4. #include <NXOpen/Annotations.hxx>/ [! s( `# m  {- i8 S
  5. #include <NXOpen/Annotations_Note.hxx>
    8 x5 U  o8 E9 ~
  6. #include <NXOpen/NXException.hxx>
    $ Y$ G3 t2 }4 C8 W8 l
  7. #include <NXOpen/NXMessageBox.hxx> // as of NX53 `! t) G$ z5 j# S
  8. #include <NXOpen/NXObject.hxx>) e5 V* Z6 l6 t, {
  9. #include <NXOpen/Selection.hxx>
    7 t9 L/ L7 Z9 X* t
  10. #include <NXOpen/Session.hxx>" h/ W6 S  Z; {- \  `8 {8 E
  11. #include <NXOpen/UI.hxx>* Y# [- G6 h3 H: n; ^9 J6 U: e

  12. . ^# ?- }- y* M. P5 t
  13. using namespace NXOpen;8 W+ o% |; x: r& [7 d' }4 h
  14. using namespace std;( p8 M; `' t. O# g: X
  15. " m  R% C8 o2 \9 R" B% R
  16. /*****************************************************************************
    3 U/ C6 z8 d7 s# o' l% M* v# t
  17. **  Activation Methods1 d: ?2 A0 s# r! D4 i. k# H9 d
  18. *****************************************************************************/* s7 {1 O; I) @# K
  19. /*  Explicit Activation
    8 c: a' j* }! l) J: n: h% j: m
  20. **      This entry point is used to activate the application explicitly, as in' r7 N! n3 @8 o" D. P7 Y
  21. **      "File->Execute UG/Open->User Function..." */4 Y+ a* w; P7 C( d0 Q
  22. extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
    7 X9 e) l& {4 X5 ]/ l& x
  23. {3 Y: y, s% V  J0 l3 m9 P
  24.     /* Initialize the API environment */: ^# `' D& ?6 S- G
  25. ( M3 u% C2 |' E0 y% x# k6 B
  26.     Session* theSession = NXOpen::Session::GetSession();
    % y& C$ h( J$ V5 y
  27. 3 L1 d5 X# h( P
  28.     try
    : n4 \: q7 p' \! p! e/ W( o4 y
  29.     {
    7 }+ U5 Q: R2 o# s4 M
  30. 4 i, N4 v! [: K2 H7 t) r+ `( c& W
  31.         // ask user to select text3 D# f4 [3 j2 u5 ]" S
  32.         UI *ui = UI::GetUI();2 z. f; E: j) Y+ O. W8 N8 {
  33.         Selection *sm = ui->SelectionManager();
    & L0 n+ u* `" H# B5 \
  34.         NXMessageBox *mb = ui->NXMessageBox(); // as of NX5
      e$ P) b1 b1 v8 `# [4 b
  35. * S0 i9 g4 P9 m7 p* H  ^
  36.         NXString message("Select Notes:");
    ! R! q/ n* l: d. H2 m
  37.         NXString title("Select Notes");2 l4 n% S+ M0 @' n% |
  38.         Selection::SelectionScope scope = Selection::SelectionScopeUseDefault;
    0 ]' y, y0 h. p+ ?- I  o2 z& a# o
  39.         Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;9 D$ `) Q- X7 q$ q/ ?; I
  40.         bool include_features = 0;
    ( w7 q  \; w  s- [' f
  41.         bool keep_highlighted = 0;) r% X1 ?8 a" I; ]) |
  42. 6 ~4 z" y2 S& A+ i
  43.         // Define the mask triple(s)% n9 H9 I: O" O8 |( v7 R' N
  44.         std::vector<Selection::MaskTriple> mask(1);
    ( w  {/ K" w. u; l& s
  45.         mask[0] = Selection::MaskTriple( UF_drafting_entity_type, UF_draft_note_subtype, 0 );
    $ H* t3 c: E" A, P. a' c  }( r
  46. : K. Y( d  ~& D) s9 N* `) [
  47.         std::vector<NXObject *> objects;
    * e% i: ~' a3 x$ g

  48. 5 A, |% l6 [% q( ~
  49.         // Select objects using filter defined by mask triples
    ' G! `! g2 `' P0 `
  50.         Selection::Response res = sm->SelectObjects(- K  `) v' i5 v! X! f! F" x  r
  51.             message,
    . w+ f- H+ N$ U" }- z2 R: I
  52.             title,! s; |& Z# R2 w& C+ U
  53.             scope,
    ' {$ H9 _/ ^: H# l) x
  54.             action,# v' S1 n$ B2 q2 u: o
  55.             include_features,
    3 v9 w' O8 }$ q' q
  56.             keep_highlighted,+ J3 L! n" a0 i3 J( E5 U6 c
  57.             mask,% `* k) k" ^( ^( V$ N8 z- h% t8 d
  58.             objects
    1 u# r1 y  ~* n3 `0 B+ Q" N6 Q
  59.             );
    ( p  u$ F9 t9 x0 R. b
  60. 2 V5 G5 n5 H5 J
  61.         if (objects.size())
    ; C; [- N/ O8 x3 r" F- C/ v
  62.         {
    # J6 [4 E  x6 |) b" C, m1 y, G
  63.             Annotations::Note *note;
    4 F# f) C" o+ P. b4 n- S& _
  64.             std::vector<NXString> messages;4 ]) `5 d& q4 s+ @. z% O; |
  65.             std::vector<NXString> texts;
    / A) a) v8 j+ }9 n: R. I+ A% `
  66.             for (unsigned int ii = 0; ii < objects.size(); ii++)
    5 c( P' q- `3 {* ]# P4 V
  67.             {
    ; B' F& v0 K+ [3 S* p5 n( `8 H
  68.                 note = dynamic_cast<Annotations::Note *>(objects[ii]);
    & U0 n* C2 Y5 ?
  69.                 texts = note->GetText();
    * f8 V# [8 S- I: o- N' T% G5 Q% J
  70.                 for(unsigned int jj=0; jj<texts.size(); jj++)) b. o+ |, b$ x2 X
  71.                 {2 w' B0 J  y4 x: N4 ^
  72.                     messages.push_back(texts[jj]);
    : i0 W$ z% J+ M8 |. a% t
  73.                 }
    7 I4 G3 t/ \/ R2 d- u
  74.             }9 [3 {5 `/ l1 t1 T$ N" F$ G8 r
  75.             // NXMessageBox works as of NX53 u5 r. t. L) x7 w
  76.             mb->Show("Selected Notes", NXMessageBox::DialogTypeInformation, messages);
    3 ~" n! y! m2 M+ D0 m
  77.             // otherwise simply write to the listing window  M; o" g$ s1 w& [
  78.             // ListingWindow *lw = theSession->GetListingWindow();
    - S9 {9 k4 D# }" g
  79.             // lw->Open();8 C( s$ {" `8 d: c5 t7 A- E: I: e
  80.             // for (unsigned int kk = 0; kk < messages.size(); kk++)
    ( i) n7 X# s* h' `3 F
  81.             // {
    2 F. d$ u' h5 z. A* V& {
  82.             //  lw->WriteLine(messages[kk].getText());2 i3 Q5 E3 b9 z. Z0 N
  83.             // }
      S5 J0 Y- L% |& D  N4 B

  84. " _& Z6 C2 \9 H3 k, S
  85.         }
    4 V( |4 Q9 \" j6 J4 |
  86.     }
    : h0 N0 x, ^2 D- L, h- h2 ^% q
  87. 0 V  }/ Y" h! Q' Q; D" h# N0 p6 A
  88.     /* Handle errors */. d% W5 ?: O) l0 U3 D5 m* y( W
  89.     caTCh ( const NXOpen::NXException& ex )
    ; _+ V8 I5 j: f, t& Q- g; i" |
  90.     {
    - n4 L8 ~9 k# `
  91.         // NXMessageBox works as of NX55 H7 J5 s$ U, {8 m
  92.         UI::GetUI()->NXMessageBox()->Show("Error", NXMessageBox::DialogTypeInformation, ex.Message());+ q8 S% K+ ]1 L- h
  93.         // Until NX4 simply write to the listing window
      U0 C! x# z6 f0 q; g! C0 A  Z
  94.         // theSession->GetListingWindow()->WriteLine(ex.GetMessage());
    1 E! n+ W& B, K* B& Z7 C, @
  95.     }2 g9 I+ o& G' c
  96. }
    1 A" W7 k7 ?/ Z' y

  97. ; C6 q4 K( C5 Q
  98. /****************************************************************************** {0 a  I4 k7 z/ A0 k" x
  99. **  Utilities
    & G3 E" N0 R& o4 W
  100. *****************************************************************************/  z0 A* v- _; \& y9 i' Y

  101. " q3 d, [4 p/ b( ?: c; I
  102. /* Unload Handler0 q" v. H8 B2 A+ m1 [; o( u( \
  103. **    This function specifies when to unload your application from Unigraphics.9 ?* E  A* m# Y7 ^
  104. **    If your application registers a callback (from a MenuScript item or a
    " ~& {0 n* P- C: J% w
  105. **    User Defined Object for example), this function MUST return) E. ^' Z: ^' {* `
  106. **    "UF_UNLOAD_UG_TERMINATE". */% p1 d" d, ?+ R
  107. extern "C" DllExport int ufusr_ask_unload()+ y  D& [" Q  S( X
  108. {$ E) d. B0 F* L" f
  109. return (int)NXOpen::Session::LibraryUnloadOptionImmediately;7 \, A  |, G. J( m/ D8 ^
  110. }
    % i6 ?/ D/ x( k) |. Y6 Y
  111. 0 V6 T% V$ C! D6 a3 C
复制代码

) y( A2 f6 X+ V' z6 J1 _' j
+ e& t, C: U3 }: S) s. X5 i" d
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了