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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。
2 u2 k: ?! Y) t- w
0 ]; y# Y& K: E/ j2 |4 H
  1. #include <stdio.h>
    4 N5 R& x+ S9 q* V2 j
  2. #include <string.h>
    ; H( ]2 V: C. ]. N7 F, V/ L
  3. #include <uf.h>
    ' V7 R( o$ V/ U! ?4 }! B2 r
  4. #include <uf_ui.h>
    0 Y  [  W9 X' w4 l+ d( s

  5. # q% _! G9 s9 M' ]) d6 g
  6. #include <NXOpen/NXException.hxx>
    0 t* t' a/ `, ^  S" V. S
  7. #include <NXOpen/Session.hxx>
    3 _0 r& a: y. N+ V+ W* E4 n
  8. #include <NXOpen/ListingWindow.hxx>* Y. [6 r4 S0 f; r
  9. #include <NXOpen/LogFile.hxx>9 _  R) n- o- V7 L+ l7 `
  10. #include <NXOpen/PDM_SessionSettings.hxx>- X. l7 O8 |4 H$ c/ G% c
  11. #include <NXOpen/Part.hxx>
    % N( R! f# S/ h! i2 j
  12. #include <NXOpen/ParTCollection.hxx>0 C; Q! l0 p( r/ V
  13. #include <NXOpen/Session.hxx>
    - r7 j( d0 U  Q' x% a& v4 T  e  F

  14. # D! |3 l2 L( ~( A
  15. using namespace NXOpen; // <== Very Important!
    - s0 d+ x7 W6 F# A( b1 k$ s

  16. / A; C) y; G- ?: z  Q. O
  17. #include <stdarg.h>, T7 k5 U& k! S8 t
  18. 2 X0 v; Z/ r! d5 k2 K9 \( `
  19. static void ECHO(char *format, ...); Y; ]- ^3 ?: N5 g2 L6 L
  20. {& q' W" X- V+ Z- D7 D
  21.     char msg[UF_UI_MAX_STRING_LEN+1];
      v* @4 w. Q. {& q+ q0 u
  22.     va_list args;
    & x9 o3 o, @- L
  23.     va_start(args, format);
    ! `% i+ D# u6 |" ?+ o' O
  24.     vsprintf(msg, format, args);8 j6 _7 N" L- m( g  Z/ E
  25.     va_end(args);* q% a9 G# |# C" Q' g
  26.     UF_UI_open_listing_window();8 c/ r' p" W7 Y/ o& R% m
  27.     UF_UI_write_listing_window(msg);& i$ b, H/ Q1 X3 m  f
  28.     UF_print_syslog(msg, FALSE);1 m7 {! B' i  m5 {+ i* E
  29. }
    $ |) q- [6 P; O) H& r

  30. 0 m; }4 p# S8 d/ O7 r( b. s
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))! m$ D3 L/ m$ u) i# G' W

  32. % a8 f5 W! e  F( U$ c
  33. static int report_error( char *file, int line, char *call, int irc): W4 U( `" z9 q# y( q6 e
  34. {
    ! {7 |9 t1 s7 W( k; i4 T, l( e& u
  35.     if (irc)0 k+ u1 c# @: q7 C
  36.     {0 @8 Y! h+ M/ i8 S# q" B: V0 K
  37.         char err[133];
    ! l/ I# i9 |: m' G6 N) g9 j

  38. & ^7 c: f( M  V! e. W( I3 v
  39.         UF_get_fail_message(irc, err);
    ; @& u8 t- s- `  D( x: ?
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",* K3 }4 i  w9 M& m0 W! B$ g
  41.             irc, line, file);
    / y( ~6 Y3 j0 h4 y, }9 n1 u
  42.         ECHO("+++ %s\n", err);
    0 P! W. C: |0 f0 ]+ Q* J
  43.         ECHO("%s;\n", call);, W9 U3 M0 k9 S; Y1 E; J
  44.     }) ~7 O+ j. L, i1 Y4 z

  45. ) q) o/ S! ]$ \& B
  46.     return(irc);
    3 `* P) w  G8 R* u5 c0 m1 G) D
  47. }; D5 d+ X4 G  }( M/ q8 S

  48. , N6 B) M- C0 ^) ]9 J/ b; S

  49. # U8 Z! s1 J; m, r& v$ u1 o. Z
  50. static void do_it(void)/ r  `% L$ i* D% g& t
  51. {( l  o! O' }9 O& U4 B! f0 x
  52.     Session *theSession = Session::GetSession();
    2 p! ]. m: x# \* l" D6 R
  53.     Part *workPart(theSession->Parts()->Work());3 u' b: W8 A2 O9 \
  54.     Part *displayPart(theSession->Parts()->Display());
    ( e, K' {* T: m' ]3 e; Q8 \
  55.    
    & w; Z' ]; |; H' V8 n0 k
  56.     PDM::SessionSettings *sessionSettings1;- B0 G  H, W! N2 T& ^' \
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();
    7 Q; n1 y% o6 ~6 _) j3 a" u# b
  58.    
    $ A( i! D0 q. G! B6 C
  59.     NXString CurrentGroup;$ K( N/ t1 d) a( {
  60.     CurrentGroup = sessionSettings1->Group();
    # x8 V. d& X0 F; Z
  61.    
    5 t0 R0 u  X, ~9 K
  62.     NXString CurrentRole;- _: y3 j7 r4 o
  63.     CurrentRole = sessionSettings1->Role();, Z- J8 o' I3 Q& |4 E
  64. ) m& @8 ~5 H7 N6 C& o& h
  65.     theSession->ListingWindow()->Open();
    1 g3 X9 _& a- [* Y
  66.     7 f8 c" c* B1 k+ j8 p" U; d
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");( R: Q8 Y* T) N3 g) O
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);1 G2 N# _6 K$ u6 J* X  {
  69.         
    ) A/ k: l2 P+ Y; n6 o
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");    9 y- H- V1 F) e' n2 ]3 A/ q' z" u
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);6 ?) Q: P( o" X5 j* @! {' e$ j
  72. 4 h% n- [8 _: K; i' j" |# S
  73. }8 M) P+ f' @  z( p' W
  74. , _' K6 m8 Z5 k9 a; R
  75. /*ARGSUSED*/- n. l6 E/ U# b! y; b' z% s; S0 r( Q
  76. void ufusr(char *param, int *retcode, int paramLen)
    9 p1 y3 m8 H: m; w6 K+ N/ g0 D
  77. {4 h! i3 B- l0 A2 d
  78.     if (UF_CALL(UF_initialize())) return;
    - `+ Q; U. ]" [2 Y& ^  |
  79.     do_it();# {/ s5 `' h" a, e( o) j# f
  80.     UF_terminate();
    ; P# e  l' K* j6 V; P! d
  81. }
    4 @# a' ~* {9 t7 K
  82. - M2 b% E# I3 e6 P9 P4 _
  83. int ufusr_ask_unload(void)
    ' V2 Q0 m- z% p: q; Z
  84. {: ?! |6 v8 k1 f: [" A; L
  85.     return (UF_UNLOAD_IMMEDIATELY);6 e' v' X# ]4 s0 q6 m" a
  86. }) M' S" }% w! f6 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二次开发专题模块培训报名开始啦

    我知道了