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

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

  [复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

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

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。
: x. t- N: g) k3 e7 L5 S3 E" a, S2 m2 T8 |' l" N2 G* h+ I
  1. #include <stdio.h>
    ( C3 @8 s7 z: S- I- l/ o) E" V
  2. #include <string.h>. C2 c) y5 |$ ]
  3. #include <uf.h>/ v- H8 O  d1 X
  4. #include <uf_ui.h>% H) m( d9 _5 i  X

  5. 1 A5 q* N% P& v. Y9 x- D
  6. #include <NXOpen/NXException.hxx>% _' t  r% H  a. U: y) O( T" j
  7. #include <NXOpen/Session.hxx>
    6 ]9 C9 y" g# f" G3 Z: Y
  8. #include <NXOpen/ListingWindow.hxx>
    % L* m+ z' x0 v8 m4 W4 I1 K; [
  9. #include <NXOpen/LogFile.hxx>. a* i/ j, ?5 M$ O. E4 e  Z, U, ]
  10. #include <NXOpen/PDM_SessionSettings.hxx>4 K7 n- o+ j* n, D+ ~0 t9 ?; V
  11. #include <NXOpen/Part.hxx>
    3 r7 u/ W/ U, q6 Q) r, N
  12. #include <NXOpen/ParTCollection.hxx>, c6 t% j# u0 V+ S7 T% m4 G
  13. #include <NXOpen/Session.hxx>% b! p0 _1 d  i2 E! Q( X
  14. & X6 k+ a9 u9 B
  15. using namespace NXOpen; // <== Very Important!
    7 D: y' R  s: w

  16. $ u' h; ?  S# ]) D3 Y9 e
  17. #include <stdarg.h>% h+ E/ t; Z6 t$ E- j  ?) Y( \

  18. ) P5 j$ t' w  ]. v: B
  19. static void ECHO(char *format, ...)  k! K$ j+ J( u6 [2 |% S6 @
  20. {: ]! e* e* v1 q3 A2 {6 C
  21.     char msg[UF_UI_MAX_STRING_LEN+1];) c7 `, u" z$ R) t! B5 S
  22.     va_list args;9 A1 R9 v9 _& W  R& j" U7 W% B
  23.     va_start(args, format);3 U7 d- Z; i" `1 }0 Z( m
  24.     vsprintf(msg, format, args);0 }) T; D* k* ~4 g
  25.     va_end(args);' S( h, L; T, ?0 q% p
  26.     UF_UI_open_listing_window();- o; j) o$ n* O' {& \
  27.     UF_UI_write_listing_window(msg);8 R  X) Q! E) |5 K, a  z
  28.     UF_print_syslog(msg, FALSE);
    ! [& V  Q- i4 G$ G/ O
  29. }4 |) l& }2 _( X1 v# D
  30. , b# k. _! o! `) {6 q  a
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
    . S2 ^' D2 Y7 ~5 f2 l' M
  32. / z) S& }8 z6 e3 s
  33. static int report_error( char *file, int line, char *call, int irc)1 \# H2 e1 W2 s* l  x# P
  34. {
    1 P8 w! J2 q5 c5 J/ `# l% F
  35.     if (irc)
    9 H* P- k2 s" _$ Z
  36.     {+ Y) J) [4 \! @" ~# L9 }* D! p
  37.         char err[133];  x0 ]) ?' \* a6 N8 S0 o. S. d
  38. 8 C+ [: i" _; B4 Y6 t7 c1 [4 q
  39.         UF_get_fail_message(irc, err);! t7 N" n* T! f/ L3 N
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",
    % o4 J5 A5 {  D4 U# y$ h
  41.             irc, line, file);
    ) Z9 Z" P) ]. _
  42.         ECHO("+++ %s\n", err);# q; _; u- x  n1 h# [" p
  43.         ECHO("%s;\n", call);: Z2 S2 b4 ~) g1 ?  P# b
  44.     }
    5 D5 K, Y- [5 z) O, }3 W; u

  45. % w, F! ]( l( K4 o& W! m! h
  46.     return(irc);2 R0 P7 U" Z3 B
  47. }
    / j, m( i8 K1 d

  48. ; x+ B" }, x( X! Y1 ?
  49. , s' r9 q. I/ D5 }5 x
  50. static void do_it(void)
    ) k6 i2 O( u. p1 n
  51. {
    9 @* J5 n# g  Z: X2 l+ ^
  52.     Session *theSession = Session::GetSession();  g% v* W; E6 P4 U1 l) I* @
  53.     Part *workPart(theSession->Parts()->Work());
    3 P$ v6 l" `5 B) B$ ~/ ^' q; s
  54.     Part *displayPart(theSession->Parts()->Display());
    ' M7 v* N3 m& K. X# h7 ]# `
  55.     & u) ?4 [/ m- i& c+ H; `4 _
  56.     PDM::SessionSettings *sessionSettings1;
    ! d0 R1 B* i/ A
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();( k9 x( d% ?, p$ l  r9 t
  58.     . b# [( d4 Y- E4 G' U/ x9 v+ |
  59.     NXString CurrentGroup;" `3 ]- P/ _' ~
  60.     CurrentGroup = sessionSettings1->Group();
    9 s) L2 w9 Y5 i! I; u# v
  61.    
    % a0 R, [( N! C: e2 W$ w7 W$ \3 N4 B
  62.     NXString CurrentRole;3 h0 T3 x# Z5 h& Y
  63.     CurrentRole = sessionSettings1->Role();# Z" W1 n1 F5 {; T  i) m) t
  64. ) W4 V% Q7 M& S3 O, U/ Z1 e
  65.     theSession->ListingWindow()->Open();, X9 e( O9 j& {& E: f
  66.     : J( ?7 x0 }/ }3 D% S  z
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");# Z/ _$ ~9 X* x7 h" ]
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);
    5 s1 A+ M( j3 |, [1 i& C! b
  69.         6 w( W4 i9 \" C- H( `( t; P  B
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");    ) p$ R" E- d" W4 D2 f$ U
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);) q# W3 q7 I* i! e

  72. ) r, Q$ V- J$ ^2 k4 p
  73. }
    - S: j6 s8 Z$ l6 g
  74. , j" Z3 N& H# e7 n' y7 E
  75. /*ARGSUSED*/
    , t; R* e7 t) r5 ]/ R
  76. void ufusr(char *param, int *retcode, int paramLen)2 O" `, J% J. M! w2 V
  77. {( `& |4 X# u# M8 P% T& N8 }) ~
  78.     if (UF_CALL(UF_initialize())) return;1 V, E: m3 b8 K
  79.     do_it();
    ! o& h. G+ i/ Z7 \6 m: v6 [6 ]5 z" F
  80.     UF_terminate();
    % d4 e/ ?1 h  y* v3 o4 e
  81. }
    # h* O3 b2 B4 e; ~. R! ^

  82. 1 i+ x6 X% F/ @% a$ x* }
  83. int ufusr_ask_unload(void)8 c# I" q- q2 F% D, Y' J0 D1 ^
  84. {
    # \3 k# {1 a8 ]  x( f  o+ s# k
  85.     return (UF_UNLOAD_IMMEDIATELY);
    ; B$ R5 v" k' o
  86. }5 W5 V. B/ [  H' `
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了