PLM之家PLMHome-工业软件践行者

[二次开发源码] NX二次开发源码分享:NXManager中,获取用户的组和角色

  [复制链接]

2019-12-10 17:53:21 4263 2

admin 发表于 2013-11-6 19:00:16 |阅读模式

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。# r+ d! K  w, V* D" M$ m( q: p/ R
2 K; p, I& K$ D/ S5 e1 J! H& D
  1. #include <stdio.h>/ h# f- S* w7 |- B0 A* C; [
  2. #include <string.h>/ z$ S6 s' f" i) o
  3. #include <uf.h>
    & @6 P; w$ _5 H4 _
  4. #include <uf_ui.h>
    0 @" V8 z( H0 k9 ?+ p! I2 T  Q* {

  5. # c# @% ?8 ~! y' n, S
  6. #include <NXOpen/NXException.hxx>$ \( d5 O$ [  S+ |) }6 \: w. @
  7. #include <NXOpen/Session.hxx>7 s( m3 b9 q8 E# M6 O3 r3 ]
  8. #include <NXOpen/ListingWindow.hxx>2 N5 b: D% H7 j) S- w
  9. #include <NXOpen/LogFile.hxx>( E5 {9 I& ]0 y- Q: }# V
  10. #include <NXOpen/PDM_SessionSettings.hxx>
      u0 {: l4 N2 S2 E! ], s( u/ d7 x; o" T
  11. #include <NXOpen/Part.hxx>. B) c) o! A" c$ e
  12. #include <NXOpen/ParTCollection.hxx>; r; A2 p/ d! G! B
  13. #include <NXOpen/Session.hxx>% S* g9 w; f% D9 h; W2 e; P
  14. % ~6 T1 t3 v, r' [* k
  15. using namespace NXOpen; // <== Very Important!& t' M) H  `* f+ D: u

  16. + P' ~) y1 I* C- @
  17. #include <stdarg.h>
    ! L; c) B9 m( N% `, l6 O

  18. ; c% w$ t4 \6 s" j8 a" x. }
  19. static void ECHO(char *format, ...)2 |4 J* e0 e, P3 b8 R  e# B
  20. {
    + |! h8 u& [7 z% z
  21.     char msg[UF_UI_MAX_STRING_LEN+1];
    2 [% q" ]6 L3 T2 A% B
  22.     va_list args;' L& T6 R7 P. b3 D6 R& F8 A5 ]
  23.     va_start(args, format);
    0 D6 ?0 k( v- S6 B
  24.     vsprintf(msg, format, args);0 t) M" w1 G5 M) j: W9 J  m9 o0 t) b
  25.     va_end(args);( K, i8 h9 h; B( w, F# o5 [7 F; K
  26.     UF_UI_open_listing_window();
    2 K$ b5 h  v0 n7 a0 C+ x5 g: |
  27.     UF_UI_write_listing_window(msg);
    * }5 f: a& d2 v& n5 d* B) A
  28.     UF_print_syslog(msg, FALSE);
      r+ K" R7 A+ k
  29. }8 v: s0 H0 c8 ~5 ]3 q8 U+ h
  30. ' B6 G7 d- D2 V! f$ x4 o. h& v
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
    * G; y- q7 w* l

  32. $ `) u9 S+ Q7 _6 X4 V0 c/ Z, X$ ~$ w
  33. static int report_error( char *file, int line, char *call, int irc)  e) w' f. R# ^3 [9 }
  34. {- D! \2 @$ t, s" N" F! F. p) q
  35.     if (irc)8 D7 u0 g7 j2 ^+ ]: v: p* C
  36.     {, s" G7 n& N, `2 T, _
  37.         char err[133];
    * T  [* x( f  b' x, ^1 p

  38. , o3 I7 W4 {$ m( u5 L5 {! ~
  39.         UF_get_fail_message(irc, err);
    ! ^2 d. t- \5 X( e. ~# F
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",+ c9 @+ P- R# B- z. X! b; ~
  41.             irc, line, file);
    & o$ S7 w! U9 E2 T/ Z7 }
  42.         ECHO("+++ %s\n", err);
    5 V! {4 |7 Z! C+ p1 R: x  {
  43.         ECHO("%s;\n", call);
    + t  M7 F; y8 ?2 L9 D
  44.     }
    " c* l6 u+ Y( U! v( y. {, f

  45. " o1 N$ C6 H( _3 |! T6 v/ f
  46.     return(irc);
    " L# S7 U0 @& D. L0 e* t
  47. }
    0 B& s2 ^  J: Y3 Z. a$ s" l) ?
  48. ; E4 @% P+ E1 ?. [7 O0 Q8 B
  49. ( P; T+ z8 z- z7 R
  50. static void do_it(void)
    ! S5 i: t" k) K! A* {/ `
  51. {
    ; x/ c8 V, q* z+ N3 M- t, y( A
  52.     Session *theSession = Session::GetSession();
    0 F8 w% w! Q' D
  53.     Part *workPart(theSession->Parts()->Work());
    + ~: ^' K7 u. ?, p1 q6 [2 ~. j2 O
  54.     Part *displayPart(theSession->Parts()->Display());$ _4 p& ?: h2 l6 l) _
  55.     / _* F& @! I4 V* d
  56.     PDM::SessionSettings *sessionSettings1;
    ; D2 c  b' ?: h1 P& r8 ~
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();" h7 V: l- f/ @* @2 k
  58.     ; y, {8 v- w- ]- E! w2 f7 q( }
  59.     NXString CurrentGroup;% _2 B; f& A3 @" }( v( H3 R2 ]
  60.     CurrentGroup = sessionSettings1->Group();
    & k( z; b6 Q1 E1 H
  61.     2 Y' W* u5 N. m7 E0 j" u6 _' \
  62.     NXString CurrentRole;
    4 R9 R- v% u* [( H& G! B! `6 }" |  Y
  63.     CurrentRole = sessionSettings1->Role();" M  F, R& {  N2 S9 _

  64. , r! }9 s; Q5 N7 o
  65.     theSession->ListingWindow()->Open();  I4 G9 ~% R: g$ Q( d
  66.     # u8 @" s$ L0 P" L; w
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");
    & T+ \" k- o  J+ `8 S6 z
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);: m7 p$ @' J/ u8 @4 i4 d% F
  69.         
    , m5 A0 W: f: k2 {
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");    4 H3 _; h% W' {6 l, |
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);+ s  }1 g. ?% ^
  72. 8 N8 h/ K# t' d  l# _/ _. u
  73. }0 X2 m/ g) J0 c2 Z2 V" U1 b0 q+ I, e' H' |
  74. 6 x/ @6 O% @9 V9 a% c  A/ G
  75. /*ARGSUSED*/
    3 E2 W6 m( L9 S& @  W! d" c
  76. void ufusr(char *param, int *retcode, int paramLen)( y2 ?6 `8 ~  _$ L/ @& {! ?/ _6 P
  77. {
    ' o7 H1 R  E9 z) A6 b  u
  78.     if (UF_CALL(UF_initialize())) return;2 z) f) m2 v8 n/ p9 l1 Y
  79.     do_it();! [* `$ M- l5 u* R0 n
  80.     UF_terminate();
    7 }3 f, R( U5 F. V
  81. }$ a* E" Z  J; i, \+ c5 X: C
  82. ! I* Z. q- J* V* [
  83. int ufusr_ask_unload(void)% G) O$ y& t8 U5 y7 t' Y
  84. {
    ' W5 e0 _3 n1 t" u0 m; @) r
  85.     return (UF_UNLOAD_IMMEDIATELY);0 r4 x* m! f3 ]) b7 ]. Y3 u/ A' Q9 e* t
  86. }
    . [4 _4 W3 m( T
复制代码
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

全部回复2

yuleihz 发表于 2016-4-16 23:42:58

yuleihz 沙发

2016-4-16 23:42:58

主要体现在哪些地方吗
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

licxsw 发表于 2019-12-10 17:53:21

licxsw 板凳

2019-12-10 17:53:21

为什么拷贝代码 会产生一连串乱码呢?是防止拷贝吗?
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了