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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。
( ~' }5 |( v$ a9 c2 W' V) M
5 r/ t" q/ T, V% V7 m) c7 G! H7 ^
  1. #include <stdio.h>; m# Y" b$ `  ^; Y1 Z1 W2 q
  2. #include <string.h>
    ! y) d) D) Z; M7 b" p: K4 B
  3. #include <uf.h>
    * I, T8 I- L( V: M$ z: r
  4. #include <uf_ui.h>
    ; T6 a8 E, e5 t# L  N+ o& A

  5. & x: C+ @7 P' j  p5 Q9 J4 ^
  6. #include <NXOpen/NXException.hxx>
    3 ^" c' I  m3 U+ R; c
  7. #include <NXOpen/Session.hxx>7 Q1 p8 E4 W& X: K' z
  8. #include <NXOpen/ListingWindow.hxx>& x  p& h1 J! ~/ Y& P6 I8 s
  9. #include <NXOpen/LogFile.hxx>9 i2 I& ]  `& U' T- {3 X- q4 C
  10. #include <NXOpen/PDM_SessionSettings.hxx>8 o- H: T) D  i# M. [- g
  11. #include <NXOpen/Part.hxx>
    $ k. ?4 F( D# P: l+ Q
  12. #include <NXOpen/ParTCollection.hxx>
    6 j' X7 p8 Z! j* V3 J
  13. #include <NXOpen/Session.hxx>
    2 C' ~4 {) l2 ^  ~, P: `/ [
  14. , [( B3 v! r/ o0 r" R7 g
  15. using namespace NXOpen; // <== Very Important!
    - S- }' a/ h9 A$ T9 A
  16. ( O% t% |2 C: N4 t
  17. #include <stdarg.h>
    & K" [; H4 |) G% ?

  18. 6 U; u3 R1 f( D$ e! Y: p: R1 a
  19. static void ECHO(char *format, ...)
    / Y; \( ]8 e1 Q* o  l( i5 w
  20. {
    3 q* {  ~( ]3 T4 Q2 o; e0 X8 K
  21.     char msg[UF_UI_MAX_STRING_LEN+1];: f3 @, u4 j4 ~2 x. m. Y% f
  22.     va_list args;
    / x- Y- u1 J) s# m/ z. H+ S
  23.     va_start(args, format);
    * c0 q% P) Z& m5 I" F0 ]3 d% r6 U
  24.     vsprintf(msg, format, args);3 @' ]7 h" R" |
  25.     va_end(args);, A6 p7 }" y0 s
  26.     UF_UI_open_listing_window();
    . W/ x7 b% e2 @; T" G) g# r8 v. f
  27.     UF_UI_write_listing_window(msg);
    ( V# T. v- Z) L% b6 m1 S! ~% h
  28.     UF_print_syslog(msg, FALSE);
    : a4 J& Q4 T4 R' r
  29. }* g/ T$ o- r1 H
  30. ! N8 S# a; b) S: h; o
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
    ' X, _: }8 _) D$ i! e

  32. 0 X1 j/ Y& D4 R  l6 `  l8 F5 s
  33. static int report_error( char *file, int line, char *call, int irc). m3 b& L6 g  S$ `- T! J& P
  34. {
    ( V- w- P: j, }" D: D3 B2 M* u
  35.     if (irc)+ p0 T3 E0 @; z$ ^9 I2 V
  36.     {3 g# l$ z0 a' Y' U2 K3 Z& S) M
  37.         char err[133];  R# s9 [6 a' k& W8 b
  38. / m0 R* R6 H& U/ n1 F0 D5 t
  39.         UF_get_fail_message(irc, err);
    ; ]% _0 G: P0 m- W6 j! `
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",1 p) M' U% a6 p5 g# P# M
  41.             irc, line, file);1 s% Z( P- U# [. z9 y# {* Z/ {
  42.         ECHO("+++ %s\n", err);
    " k' k: a3 C( d9 o
  43.         ECHO("%s;\n", call);
    ' W& V/ m( \8 J! H4 p- k- k
  44.     }
    , Q4 s" h# {, i5 ~

  45. 1 c  ]1 Y& d6 v( B6 p. B; `2 f
  46.     return(irc);% ?' J( W) b" E( ~+ H/ S
  47. }
    . R" j& M9 A( C2 M

  48. * l- J! x9 G/ a  D% Z3 d

  49. ( n  x& ~+ Y# b& X( H1 r
  50. static void do_it(void)( D3 e: z7 m  U  N1 ?/ ?
  51. {
    8 C8 I6 n* O* `
  52.     Session *theSession = Session::GetSession();
    * Y/ h# e! _9 I1 \- l, j* m
  53.     Part *workPart(theSession->Parts()->Work());
    # ?6 Q5 O% D6 {& f! F
  54.     Part *displayPart(theSession->Parts()->Display());( \, s  o  P: s# F4 ?$ E4 m
  55.     * l2 a+ {/ f3 b* Z' d/ Y% A& j
  56.     PDM::SessionSettings *sessionSettings1;5 q. B6 v$ H# W* J) c3 [: R
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();
    ' \/ e/ x" y+ a- o/ S
  58.    
    % J3 y# q) ^0 [* [
  59.     NXString CurrentGroup;
    , {. \1 |( b) d9 f$ X* M- B
  60.     CurrentGroup = sessionSettings1->Group();. q# P9 h, e  J
  61.     5 H7 B/ u6 L4 g) n7 n8 \
  62.     NXString CurrentRole;1 n% V# A, C1 T8 Q
  63.     CurrentRole = sessionSettings1->Role();6 }  j/ K$ ~% c" T2 T

  64. ! a* [. g  H, ~* @$ h1 Y3 K
  65.     theSession->ListingWindow()->Open();
    & _% e7 `9 K! D3 F3 ^' u
  66.       E% r; I& R# p3 R% ^. w
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");
    5 M# j& u- j5 `. }; O/ k$ m% m* _
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);
    5 F: k; ?: t9 N3 |4 w7 x0 s: ~0 t
  69.         
    3 i  k/ p# K1 D3 ]' ]& f1 J
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");    0 W  s2 y4 n9 p
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);
    ; b5 c0 Q7 Y' O9 i

  72. 3 I7 c1 U. b- [0 I
  73. }
    ' x$ ~& C! a- Z$ [, ~
  74. 9 F; ]5 D0 O4 }; f* R
  75. /*ARGSUSED*/. W, z3 @3 M  V6 o* i3 u
  76. void ufusr(char *param, int *retcode, int paramLen)" c+ {* n2 ^- W) z
  77. {7 M$ N0 e, o# n5 l! x6 y4 P  {
  78.     if (UF_CALL(UF_initialize())) return;
    1 g& }; ^# Z" I/ Q5 e4 D
  79.     do_it();( i" l* g. ~/ x* f. F* {
  80.     UF_terminate();7 I3 J! ~/ H$ n, j1 I0 ]6 S. U) a
  81. }
    ' u; H2 M1 e* h3 |

  82. / o2 \' u. t, ~5 y- |( V
  83. int ufusr_ask_unload(void)1 C& |" r+ v* @9 [6 \  |
  84. {
    7 x6 S$ _$ P- n1 ?4 V
  85.     return (UF_UNLOAD_IMMEDIATELY);) T9 N- b$ T0 L6 f4 @
  86. }5 \/ G/ k& v7 u, B& @9 A$ R$ a
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了