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

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

  [复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82162
QQ
发表于 2013-11-6 19:00:16 | 显示全部楼层 |阅读模式

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。% E: [. E* \& u7 A$ B. G

; Q! c' Z* `3 p8 \
  1. #include <stdio.h>
    ) v/ b) q7 K. ]& p5 a  S2 h& D1 k
  2. #include <string.h>
    ; @4 i5 |# x% e, q5 p. _; O
  3. #include <uf.h>
    ; l/ j( E( z6 |3 t
  4. #include <uf_ui.h>
    7 W  _8 f4 N' n
  5. / L1 J+ t1 s4 I! T$ B3 m) D* R
  6. #include <NXOpen/NXException.hxx>+ j1 i7 p2 {5 S$ s" ]
  7. #include <NXOpen/Session.hxx>! t5 O- E4 w& b! j+ C$ I
  8. #include <NXOpen/ListingWindow.hxx>
    2 R0 g' Z: Q: V5 D5 r' |9 U
  9. #include <NXOpen/LogFile.hxx>' B* u4 t( Q: s+ b, k5 J- s  z5 v
  10. #include <NXOpen/PDM_SessionSettings.hxx>. D4 P& x7 k2 C7 _
  11. #include <NXOpen/Part.hxx>! C. E/ f8 J1 {' g( V
  12. #include <NXOpen/ParTCollection.hxx>
    9 Y* E! s0 G2 q+ }$ [5 ]7 \) z) s
  13. #include <NXOpen/Session.hxx>$ b  B/ J/ ?8 F8 J# A& t0 w

  14. # b& c) x- F$ r2 X+ j" c
  15. using namespace NXOpen; // <== Very Important!/ ~. c: \& D% |9 w
  16. ( m! v  B2 F* w: I- Y0 T
  17. #include <stdarg.h>
    ' t& `, T' z4 x

  18. * P1 b- G% S" z" P2 c7 H" h3 e/ e' M
  19. static void ECHO(char *format, ...)
    4 x: _( \* L' t5 y$ \
  20. {- R5 `# E+ Q- \; O$ ^
  21.     char msg[UF_UI_MAX_STRING_LEN+1];
    & R  ]2 x( P6 G! M8 M0 c, K
  22.     va_list args;9 g( [6 l7 N7 j1 k
  23.     va_start(args, format);$ U2 z5 t2 i7 T  n6 R
  24.     vsprintf(msg, format, args);# T  O- k" b) h' n' W% n" F4 s
  25.     va_end(args);9 s8 n. b% y, _
  26.     UF_UI_open_listing_window();
    * |# y9 v* z$ X& r$ n
  27.     UF_UI_write_listing_window(msg);
      X7 n& t0 O( i" q5 n
  28.     UF_print_syslog(msg, FALSE);( F/ W2 V' L4 F$ x+ N0 c
  29. }- U2 ^2 X3 ?- ^0 b* Q1 [, s3 b
  30. , e; C* M" ?9 a" T5 O& ^& M8 c
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
    " I4 r& W8 U% j
  32.   z+ L  Z3 y9 }: S0 H0 b, J
  33. static int report_error( char *file, int line, char *call, int irc)
    5 y" P" [: o. I# I9 W: E
  34. {
    * z; I8 ~) c( D8 _
  35.     if (irc)
    * [5 h/ z3 Y* w0 `3 l
  36.     {! ^& S! Q$ a6 U
  37.         char err[133];
      R) T* W' r) A7 K" @  G

  38. 7 q  p, `8 s0 m3 k. V+ x' a0 O' a$ b
  39.         UF_get_fail_message(irc, err);0 u/ p+ Y8 q' L3 f
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",
    * `- i# ?2 i9 l- b7 B! I4 Z# n  o
  41.             irc, line, file);7 _' U% A/ B+ b% N/ L+ m- X5 w
  42.         ECHO("+++ %s\n", err);8 l$ V" R+ h; k  s* A- Q1 {
  43.         ECHO("%s;\n", call);
    ( x$ u) S7 Z2 Y# N) [
  44.     }
    , l4 J1 ~7 @" {$ h/ g

  45. $ k/ u$ E1 I6 [7 L  t
  46.     return(irc);
    7 l2 C  d/ R/ E  R- }
  47. }8 T" k' j6 G$ F) W0 Y' g* R
  48. 8 d2 V3 U% Q$ P0 |
  49. ( c+ g4 V; B, a) l6 d2 p
  50. static void do_it(void)) X0 z0 G: ]2 p: e: X3 P$ B( A% B
  51. {
    * R. G  `+ C! E
  52.     Session *theSession = Session::GetSession();. ^8 l' T# q$ e1 r  f+ u0 V
  53.     Part *workPart(theSession->Parts()->Work());
    2 E& M* W' @. q5 d9 Q8 ^
  54.     Part *displayPart(theSession->Parts()->Display());
    $ h8 c) z$ ~2 p( _% o# {
  55.    
    ) z9 p, ]* _3 L  A# s- S+ w( c7 j, b7 Q
  56.     PDM::SessionSettings *sessionSettings1;
    7 H, G. T3 X% m: F. L8 L+ ]
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();
    ' @* b; m+ n( n  ?
  58.    
    0 u3 I; ]1 L$ R% J7 T  N6 c
  59.     NXString CurrentGroup;
    - P3 D! b% ~3 ?& V5 x
  60.     CurrentGroup = sessionSettings1->Group();
    0 S& n# _2 V! L& R' G* F) f, N
  61.    
    7 N3 f- A( g, G
  62.     NXString CurrentRole;) M: r: v- C: z) O3 c
  63.     CurrentRole = sessionSettings1->Role();
    ( Y- h% ?. b$ b2 Y

  64. 3 g; t& h8 ~4 O0 {+ f6 t* p
  65.     theSession->ListingWindow()->Open();
    / I/ B: p: ?: T, W$ K1 C% k. V
  66.    
    * ~9 W# f, ]) J
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");
    8 d5 A: k7 ~7 r4 u+ r
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);
    8 \: v" u' U* B
  69.         
    5 D( u& }  W! t8 ~8 J
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");   
    ! ?3 w8 D2 u8 Q$ E1 ~8 s: Q* O+ w* _
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);
    1 B! y: H# G  F8 s1 p0 t

  72. : w- @2 }' K) x$ f4 B
  73. }# j& v7 X/ e1 X# Z+ W* x* f

  74. ! _: T2 Y* T; j! ?; B
  75. /*ARGSUSED*/! l/ t8 A% B# i9 M6 j! Y$ c
  76. void ufusr(char *param, int *retcode, int paramLen)
    2 S0 `' p6 P/ i
  77. {! F4 t/ v9 p& Q8 y
  78.     if (UF_CALL(UF_initialize())) return;' \1 r  u  f% ]& B- T: m
  79.     do_it();- [& N) w  U7 L0 ~5 O0 x0 ^9 }& B
  80.     UF_terminate();+ V8 U) m6 `3 j1 B- X1 W
  81. }
    ) b0 C1 ^2 x* _' T1 l6 L5 h6 P
  82. 6 j/ Z) v/ U$ R' m- n/ g- v
  83. int ufusr_ask_unload(void)" P& v! _) @4 O5 d+ c7 _7 [: ?
  84. {
    ! f# {% h7 r7 S$ J& d
  85.     return (UF_UNLOAD_IMMEDIATELY);
    ! f$ O. {1 g* }& Q6 D: `9 |
  86. }
    ) ], V& }+ W# Q9 O
复制代码
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

全部回复2

1

主题

62

回帖

398

积分

中级会员

积分
398
发表于 2016-4-16 23:42:58 | 显示全部楼层
主要体现在哪些地方吗
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

1

主题

45

回帖

203

积分

培训VIP会员

积分
203
发表于 2019-12-10 17:53:21 | 显示全部楼层
为什么拷贝代码 会产生一连串乱码呢?是防止拷贝吗?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

发表回复

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

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

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

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

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

    我知道了