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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。1 I' H* t# t# Z. n' U

' H# k" M# _0 m" T
  1. #include <stdio.h>: @6 l. S1 F9 L( u
  2. #include <string.h>
    ) j$ ~- Q/ f. o  b9 b+ C' |$ T6 _
  3. #include <uf.h>1 Z1 `! n9 k# m9 m& [6 i3 x4 G
  4. #include <uf_ui.h>
    & l" K4 b; @4 @4 X9 _9 A% L( w- A
  5.   e/ x9 B% Y2 e2 d. m+ D3 \$ Q
  6. #include <NXOpen/NXException.hxx>% a* F4 L/ i! i/ ]$ I5 y: u
  7. #include <NXOpen/Session.hxx>  `5 ~9 n: s$ V; a; T6 U
  8. #include <NXOpen/ListingWindow.hxx>
    / y& M' s. @3 Z  A4 y  k3 H
  9. #include <NXOpen/LogFile.hxx>
    5 f5 p$ z: z1 D. \& W2 B
  10. #include <NXOpen/PDM_SessionSettings.hxx>
    % G; R! h  o- e% B
  11. #include <NXOpen/Part.hxx>
    1 S" i/ f5 \8 r1 X
  12. #include <NXOpen/ParTCollection.hxx>
    & l9 [, V# ~+ R$ u
  13. #include <NXOpen/Session.hxx>6 E; w* }5 c* u9 |3 H  ]" }+ C; ]

  14. . P, \9 _: G8 {3 Z8 M
  15. using namespace NXOpen; // <== Very Important!
    5 x4 N/ K3 b6 ^- D
  16. - H0 {; y* z* n7 `2 j
  17. #include <stdarg.h>. R/ m- p  q' Z/ ~; e7 T
  18. / ]/ B2 o. h! @. g
  19. static void ECHO(char *format, ...)
    ( S+ i  j& I3 m5 p2 X
  20. {
    5 L$ e- l  h( H* W/ H4 j
  21.     char msg[UF_UI_MAX_STRING_LEN+1];
    # b$ Q/ ?5 {  a7 @) T
  22.     va_list args;3 K; u$ A# Z1 w3 b# a
  23.     va_start(args, format);
    8 n6 Y0 u: c1 a, ?. c( L( J/ y
  24.     vsprintf(msg, format, args);
    5 b$ Q/ h- w0 Z* }9 S6 P
  25.     va_end(args);3 F9 P5 _6 i& `; E! @. i
  26.     UF_UI_open_listing_window();
    ; J+ J! Y" F6 [
  27.     UF_UI_write_listing_window(msg);" a; m- f8 |7 I8 w# r! ?2 T- T
  28.     UF_print_syslog(msg, FALSE);, q# |$ _* W+ l7 p! z( D
  29. }. D) Y4 E) {3 g) _8 m. m5 d7 ~' q
  30. % `: ]6 c  y/ P# B9 ^9 k
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
    2 N) ?, G8 r, X! D; G2 M
  32. 4 ]+ f5 S2 W' q& j! ?
  33. static int report_error( char *file, int line, char *call, int irc)
    4 Q7 a( K/ }' U+ x* C
  34. {8 y4 {) @/ q. f
  35.     if (irc)6 j9 Z5 H* L7 a2 g: N
  36.     {) n% t+ s$ H1 ~" e+ D1 T4 q5 W4 c
  37.         char err[133];
    1 K2 Q1 }4 o. y- @
  38. * N8 x$ |: T& I# n
  39.         UF_get_fail_message(irc, err);3 k2 z5 }8 b; R- E7 ]
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",; ~" }* H4 I0 @# e" ?, d! g% K$ V
  41.             irc, line, file);. k) K7 `9 C) ^9 f* K7 R
  42.         ECHO("+++ %s\n", err);. C; `+ }. X/ W" Q
  43.         ECHO("%s;\n", call);  v/ U7 o3 s" k+ s
  44.     }" R$ p4 S" v; y: b  |" M* p5 G

  45. 0 F/ E2 _& `$ \6 x/ l6 O  j
  46.     return(irc);' _' ~0 K3 O6 x
  47. }
    . b* K/ D& @$ Q* F4 T. N+ }7 r

  48. ; x7 ^1 ?$ W0 z) k: O) N$ B
  49. 6 g( `7 z+ p- J; |8 e- U" [
  50. static void do_it(void)
    8 E8 D# C) u% B- T7 I  u
  51. {
    ! s& [- z2 H, s
  52.     Session *theSession = Session::GetSession();
    9 m0 x$ }3 F8 b- w. e- D1 w
  53.     Part *workPart(theSession->Parts()->Work());  E( M6 E& n) ?( |
  54.     Part *displayPart(theSession->Parts()->Display());- X* j+ ]& M3 O; y6 \; e" p# D
  55.    
    " @% W' d6 ~. l+ A8 {
  56.     PDM::SessionSettings *sessionSettings1;
    # \: o. a6 \- S  w1 a8 \9 o
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();/ D' y: K/ f* _1 l/ E# |
  58.    
    0 q* k0 D1 i7 T; e8 Q1 V
  59.     NXString CurrentGroup;9 k1 F8 d6 _& A
  60.     CurrentGroup = sessionSettings1->Group();
    - H7 b6 _4 `+ @4 U+ a4 [
  61.    
    3 o! c) E. A; V: W& @& C
  62.     NXString CurrentRole;
    , h9 L. Z/ ~7 `% k% B" w9 P
  63.     CurrentRole = sessionSettings1->Role();
    1 c( C% G8 ~6 ?; Y- ~8 u6 [
  64. 0 l" }. N" Q' ^; J2 R
  65.     theSession->ListingWindow()->Open();+ T6 V! x3 P% y- _& Y, ~# ]* C
  66.     4 A; h' K( V8 |9 U3 b: r. R$ d
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");4 D+ ^4 Q1 N9 y. @# s. ~/ v/ _
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);! [; b2 V% i$ X2 f# H
  69.         ! o( F, [& d( L7 H) L6 m3 S  j
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");    1 s0 e' f! D7 Q
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);' y; s+ a, [% a$ n" r  B% S  F

  72. 7 u$ _7 E% Y" a( C
  73. }
    1 I: F0 `3 S0 m

  74. - R! N( k3 u) j5 Y) n; ^4 ?
  75. /*ARGSUSED*/
    * C$ {9 P9 _& C+ o9 h6 ^& p) u
  76. void ufusr(char *param, int *retcode, int paramLen)) i$ {- E( k- Q6 C2 M
  77. {5 S' k, ]0 ~( ~, h  y: h
  78.     if (UF_CALL(UF_initialize())) return;; i$ N% n3 d8 b. A3 `: U+ q
  79.     do_it();
    ! K" X* I* k: X$ _
  80.     UF_terminate();/ \  W7 h8 m" o4 E% L. l" q
  81. }
    9 ~+ x1 X2 t% f3 u! F7 c6 R; O

  82. / }$ q: b. w% X6 J. V( u7 P: J
  83. int ufusr_ask_unload(void)
    + U; W' J! p/ R: b) H) `8 w
  84. {6 R, E5 r  V3 x9 C
  85.     return (UF_UNLOAD_IMMEDIATELY);  e% q- b7 I3 k( ], s
  86. }" J$ O  ?" {/ B# o& ^
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了