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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。* E9 R7 P: }/ z4 n; k

- d- e8 P; u: f$ q
  1. #include <stdio.h>( N' l0 C* Y# v- P( y
  2. #include <string.h>3 b+ v  K# l, q# t6 u
  3. #include <uf.h>3 K4 o8 e# }" N2 |& U/ g, K
  4. #include <uf_ui.h>
    ( B8 M; h% B# N' S" @* v

  5. / {1 C6 J+ M% x( F
  6. #include <NXOpen/NXException.hxx>
    4 Z+ o" H2 y) ~9 ^* v
  7. #include <NXOpen/Session.hxx># K* R+ X" @, r9 Q7 c
  8. #include <NXOpen/ListingWindow.hxx>2 T0 J6 Y# n% y) t9 _
  9. #include <NXOpen/LogFile.hxx>+ X5 y  R8 S9 G, e" c
  10. #include <NXOpen/PDM_SessionSettings.hxx>
    0 e# r3 Y9 y3 u+ v. E" Q, B
  11. #include <NXOpen/Part.hxx>3 G2 s7 b7 `1 {: o1 P, u
  12. #include <NXOpen/ParTCollection.hxx>5 L- @4 H2 r4 B; O9 f$ z, h8 Y
  13. #include <NXOpen/Session.hxx>
    4 K4 Z$ A" z; N6 y
  14. ( U, o9 G2 [: W+ C* Z* d
  15. using namespace NXOpen; // <== Very Important!
    3 [) W8 t: t0 W1 t

  16. $ ]4 f" p) M0 W( @7 _
  17. #include <stdarg.h>2 c$ V0 U3 A8 y7 ?
  18. ( A0 f, O! w* d1 s* A) w
  19. static void ECHO(char *format, ...)
    ) a, I6 ~! a7 \% j* @# Z
  20. {
    ! c# P% `4 ~  }! T* n6 B
  21.     char msg[UF_UI_MAX_STRING_LEN+1];
    ( b& g/ ?* [6 y
  22.     va_list args;
    ! T$ x; r% W' j) }8 B# _) _) ]- ]
  23.     va_start(args, format);
    - Z8 G' v- g7 m) B
  24.     vsprintf(msg, format, args);
    ! S, a; Q8 u; R
  25.     va_end(args);
    . Z: w# u1 U% I" ^" l
  26.     UF_UI_open_listing_window();
    / N  }1 {. A; ^$ t  c- T, l
  27.     UF_UI_write_listing_window(msg);
    * I! n7 _6 N5 T% B
  28.     UF_print_syslog(msg, FALSE);/ B( N; u2 |7 Z( _* C: ?% b
  29. }& S; x% {& V& |2 `6 o( q6 _

  30. ; |2 h3 ?5 h$ I# ]5 [( N
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
    * s6 v1 h1 R, r  T% x

  32. ) d" C4 y! A! d5 y7 M9 E# z* U
  33. static int report_error( char *file, int line, char *call, int irc)  k: w$ L7 ^3 K9 k2 I) S* m4 M% Z# P
  34. {
    ! N0 {2 q1 [) i- ^7 s1 ^8 {; J
  35.     if (irc); e! `4 P5 t- k# T3 R
  36.     {
    ) E3 [7 L* F3 q, y
  37.         char err[133];
    0 E' `" q0 w. D  g" ^% J
  38. 7 ^. M6 c' u0 r/ H
  39.         UF_get_fail_message(irc, err);. i: ^4 y" y- p0 T5 f0 b5 o
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",
    4 B% F1 k) C, l8 I
  41.             irc, line, file);
    0 {; X, I1 A  V% y0 `6 W$ r& W
  42.         ECHO("+++ %s\n", err);6 G# M5 x) m$ x( O2 j! {, V) g
  43.         ECHO("%s;\n", call);' P: P! s* T* J3 E
  44.     }
    : C$ b: G9 \' n

  45. 9 k0 e7 F& J8 |7 c9 W: n
  46.     return(irc);
    3 c& k- d, n; m4 e; N8 V) O, k! C0 ^
  47. }# m; {% q( P, u9 }' Q7 k) d6 w9 n
  48. " ?: f! ?4 A1 j+ M& z0 j" j
  49. 4 v2 r0 }3 m8 ~8 a7 p, x9 B
  50. static void do_it(void)
    4 ~. W) L8 F1 u/ V9 r% j
  51. {! `& b  Q# k- O& W
  52.     Session *theSession = Session::GetSession();
    * G# y9 K" g5 b- \- \( ?
  53.     Part *workPart(theSession->Parts()->Work());2 Q6 {+ o. s! q; R. u
  54.     Part *displayPart(theSession->Parts()->Display());! S+ P7 ]  }7 ~4 g$ n% v2 ]
  55.    
      S' W2 w9 ^) x  v5 X$ Y
  56.     PDM::SessionSettings *sessionSettings1;, m" R4 _0 F/ g6 o/ @( x
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();/ E1 m: Y( E3 y. _' K
  58.    
    ; E5 H* n0 z) t/ G- l
  59.     NXString CurrentGroup;  U* @2 f7 h* H7 l3 D; I* B
  60.     CurrentGroup = sessionSettings1->Group();
    / {7 m: W  |; H. M. z
  61.    
    ( T8 h7 j' P$ r5 g9 T* `
  62.     NXString CurrentRole;# m+ z/ T( B% O2 ]
  63.     CurrentRole = sessionSettings1->Role();/ N' D: }# k, }- Z1 O  y
  64. & T* R5 Z/ j; k) v
  65.     theSession->ListingWindow()->Open();8 W; f3 Q& v! e+ z. s
  66.    
    # i7 l; d! _" Y0 z5 k8 Z8 k/ K4 ]
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");
    " u3 e1 t# r4 h5 \: ]0 s
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);
    $ r3 }6 E+ b% {, w& H# `
  69.         % A. \' J. k. ?3 E
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");   
    " ~: ~& ^; _# @, u' X
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);. u2 ~2 \& l* e: P( k
  72. ( t" w% G. m5 Q0 C
  73. }
    / V; [* L! ^, W+ H2 u9 u+ W
  74. " O5 N( e/ U3 P) l# R( E; h; k/ N# y6 V
  75. /*ARGSUSED*/
    $ w2 g, e- K& D! Z5 c6 e9 y
  76. void ufusr(char *param, int *retcode, int paramLen): Q6 D# Q* q2 ~" I- o
  77. {0 p) s5 i, J2 U8 ^1 U
  78.     if (UF_CALL(UF_initialize())) return;$ _7 Z/ B: l1 }+ S* @; t
  79.     do_it();% u1 q. h: u2 B% ~. r7 S
  80.     UF_terminate();
    , o5 d2 P) G5 r7 y% w% G4 _
  81. }
    9 k) b) D3 l( Y- o
  82. 6 \$ j. e1 f. O. ^
  83. int ufusr_ask_unload(void)8 p$ l7 c3 n/ x5 [- a
  84. {% u- l  t1 @( z) f! R
  85.     return (UF_UNLOAD_IMMEDIATELY);& z/ ]. T) S# F* N
  86. }
    4 z- Y' V% D0 J
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了