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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。, O/ Y0 ~+ e) W4 q) T

+ _1 }* I0 C- Z' K6 U5 S+ s8 p
  1. #include <stdio.h>
    ! L4 M) K* o+ Q4 K
  2. #include <string.h>
    0 T5 K1 ?- h( g( r7 v
  3. #include <uf.h>7 q  J1 e/ t( _4 L/ M* Z
  4. #include <uf_ui.h>
    3 L! u, k! j6 J. [
  5. 9 r1 C  y5 b; S( ^- q
  6. #include <NXOpen/NXException.hxx>
    " J; G2 T, ]/ M1 Q
  7. #include <NXOpen/Session.hxx>
    6 L3 j, t; P, C) E& j5 t- s
  8. #include <NXOpen/ListingWindow.hxx>
    " P% F7 a  z2 w, \. T  `( _% _
  9. #include <NXOpen/LogFile.hxx>4 X/ i  r0 m9 W, O5 A6 P0 Q6 U
  10. #include <NXOpen/PDM_SessionSettings.hxx># ~4 x  k/ I" ^. h8 p. a
  11. #include <NXOpen/Part.hxx>
    6 u- t6 x4 _1 y5 t
  12. #include <NXOpen/ParTCollection.hxx>
    8 f9 C: |  Y1 K$ _) T$ S
  13. #include <NXOpen/Session.hxx>$ C- n; _! a2 R) {# Q* F
  14. $ @6 ^8 f& W3 a! G' f
  15. using namespace NXOpen; // <== Very Important!; w# J$ M9 m0 @" O% G

  16. " z: b0 M1 f1 i
  17. #include <stdarg.h>
    # D1 K3 K8 m" m; M% f
  18. & s) V7 u) @* R6 G
  19. static void ECHO(char *format, ...)
    / G9 `0 C# e( o8 V8 Y
  20. {) s( E# M, f3 P+ W* r
  21.     char msg[UF_UI_MAX_STRING_LEN+1];( D/ C  D! A& U
  22.     va_list args;" h8 S5 q) W1 r
  23.     va_start(args, format);4 W2 ~( u7 J4 w; Z0 ?% l: i
  24.     vsprintf(msg, format, args);
    8 E& ~8 x+ y2 Z/ A- I! n
  25.     va_end(args);
    $ N# F3 \$ u0 ]7 u4 D4 B- Z) x
  26.     UF_UI_open_listing_window();
    # a( i* D# Y9 ~. c: i) H
  27.     UF_UI_write_listing_window(msg);# p' n: |$ j- X) j
  28.     UF_print_syslog(msg, FALSE);1 S8 i9 y  B5 C2 A! `
  29. }
    ; O2 P8 d* Q3 Q1 @& R9 A
  30. * _& c/ ]) ^' l# z+ z. K
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))8 L* ^( \( ]) c3 A$ x; ^2 B  j

  32. 3 ?* g* n% U9 W! x/ P
  33. static int report_error( char *file, int line, char *call, int irc)
    1 j5 B, S$ Q( J2 J6 m
  34. {
    0 S0 x9 U8 |) S1 k: l. d! I6 p. p5 M
  35.     if (irc)
    $ V- Z) z% P; y' e2 Y% u
  36.     {2 H5 [; Q: l. c+ T
  37.         char err[133];
    8 \# V( _1 M( k( y  X
  38. 8 _5 S: G9 I$ b% [+ k6 M  D7 p
  39.         UF_get_fail_message(irc, err);; R+ h: r0 t, V: O4 k- [5 {) T
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",
    5 C$ }- C. |7 k5 r  j
  41.             irc, line, file);
    ' `! f4 N- y# i, o3 F3 m4 a& R
  42.         ECHO("+++ %s\n", err);' y2 _8 a$ w! J$ a
  43.         ECHO("%s;\n", call);5 E# I' W2 z3 R8 R/ l" ~. d2 @" R
  44.     }
    0 ?0 Y8 w) F$ ]; b  m5 r2 x, S# W

  45. 8 x, X3 c) J6 J  `" }2 S5 Z
  46.     return(irc);, \: j5 r, r& ^7 P, b3 X6 S8 S
  47. }2 l2 w9 r" W/ k0 b* f& j

  48. ) d' o" h: u9 I6 A. ]

  49. # {/ e3 J. n, h6 ]/ |
  50. static void do_it(void)$ G: s  A+ v& V9 X, w, E
  51. {
    5 I1 [6 H) K# k7 k
  52.     Session *theSession = Session::GetSession();
    7 D- F: t0 V. q" d! a3 d  u, @) j
  53.     Part *workPart(theSession->Parts()->Work());
    3 _$ J; V5 ]9 ^% E5 }) ^3 u
  54.     Part *displayPart(theSession->Parts()->Display());
    8 R" L7 y' v5 D. K
  55.     1 P' P. {7 O- n$ l# k
  56.     PDM::SessionSettings *sessionSettings1;  r4 F) D4 `' l/ _3 o+ g5 b
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();. j9 a2 a; [; C9 Z' C3 h: j' f6 U
  58.     ( G( X7 h0 k5 Y2 H2 M, ?& F4 h9 f
  59.     NXString CurrentGroup;) \5 h" b/ C$ d0 ~, s2 b3 t
  60.     CurrentGroup = sessionSettings1->Group();  [6 R) S1 \. a0 _+ j+ H+ ]
  61.    
    # v3 ^! p, P8 T/ J
  62.     NXString CurrentRole;  B5 i, a2 _" H3 b
  63.     CurrentRole = sessionSettings1->Role();) K" a" o1 F5 h& ^, L
  64. ; d0 C1 l& k# @  a& N
  65.     theSession->ListingWindow()->Open();- B2 Z9 u  @# Y) ~
  66.    
    ( @1 f! J5 U: R+ Y' u# @
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");
    , _3 o0 Q4 E3 L$ V) S1 [5 W$ u
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);- R1 B8 j$ h7 E0 f3 _
  69.         ) [! ~  l+ t% f/ ]! k/ O/ D
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");   
    + K5 [+ M7 a# P7 a. @# z2 v
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);! l5 _/ T( E/ ]/ P1 Y) T

  72. 7 a0 q" ]; v4 |! G; o- E& P
  73. }
    , d3 K. V% H' n' W

  74. ! h/ o9 V- S) g8 D  m3 s
  75. /*ARGSUSED*/
    # J  G% v# t; a( s- X
  76. void ufusr(char *param, int *retcode, int paramLen)) g. y+ }' c/ [% w4 H& p
  77. {5 h2 Q) U; x, X
  78.     if (UF_CALL(UF_initialize())) return;
    8 X1 g. Z. i2 o$ ^: i
  79.     do_it();0 W  l& M7 _! L5 k- E+ Y8 U
  80.     UF_terminate();
    ( ]' N3 C* c0 r) J& G
  81. }# g1 @. L1 r( w, h3 E$ l& g

  82. " C. K, f( q, h0 _
  83. int ufusr_ask_unload(void); i  y* F% }; P! e) h
  84. {  L3 X7 z2 g) _2 I6 W& h0 `  N
  85.     return (UF_UNLOAD_IMMEDIATELY);& Q" A7 u3 F2 E* L
  86. }
    0 r% ?- x2 j& v- k. a5 T5 i/ f" Q( R
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了