PLM之家PLMHome-工业软件与AI结合践行者

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。
7 n' ~. w3 T8 p6 z, y, _2 t# x5 H# E8 H9 r; Y/ S0 Y1 c
  1. #include <stdio.h>6 J" i; C; e' n8 l
  2. #include <string.h>
    8 B: [7 {) C# Y- ?2 j
  3. #include <uf.h>+ Q( b: ]  p3 m3 u4 |( a: g
  4. #include <uf_ui.h>3 \( E6 z$ `/ K
  5. ! W/ M& z. y, g" F# O
  6. #include <NXOpen/NXException.hxx>
    5 l/ @2 ]4 ^" I0 A$ v7 d5 F/ x* W+ I
  7. #include <NXOpen/Session.hxx>
    / k- _* [. D* E5 o
  8. #include <NXOpen/ListingWindow.hxx>
    " O" L$ F" Z% [9 o( ]
  9. #include <NXOpen/LogFile.hxx>
    $ O8 [5 Z" E# a3 B
  10. #include <NXOpen/PDM_SessionSettings.hxx>9 X" k( \! o# O: h
  11. #include <NXOpen/Part.hxx>
    & o1 v* m/ z1 W4 x" \; f6 o% L
  12. #include <NXOpen/ParTCollection.hxx>
    , X( y* p0 e) O% `. }! L4 U0 M
  13. #include <NXOpen/Session.hxx>$ l  L: W* T& i8 c5 Z
  14. ! S% a" r* e( z0 v: C, t
  15. using namespace NXOpen; // <== Very Important!
    ! r* d# j" B- O6 u& l+ ^
  16. ) A; [5 l% I4 Q
  17. #include <stdarg.h>
    9 B/ p8 [; C! {" Z+ a+ ^2 Y, z
  18. 3 k: T" o' g( W) Y# S+ _
  19. static void ECHO(char *format, ...)
    9 X8 G' |8 [* l; n% P$ k6 [
  20. {
    / |$ E$ a/ B& \- E0 W9 \
  21.     char msg[UF_UI_MAX_STRING_LEN+1];5 D" _0 Z- d% l3 s$ z; {
  22.     va_list args;
    - Q) J% Q. E! i
  23.     va_start(args, format);' w0 X0 k" h" Z4 B2 ^( ?- {7 V
  24.     vsprintf(msg, format, args);
    $ v3 g7 J# o1 T5 ^$ q( L
  25.     va_end(args);- x; T/ w$ [% [+ k8 G1 O
  26.     UF_UI_open_listing_window();7 j. t# ?) g( ?4 N! s+ x
  27.     UF_UI_write_listing_window(msg);
    6 l+ h3 a, [8 r7 ^1 c9 N
  28.     UF_print_syslog(msg, FALSE);$ a2 ^' ?2 ^/ `5 ~0 d0 T, s
  29. }
    ; [$ s& t/ t* b! ~( U3 B
  30. % z9 ?9 Z5 X3 l/ i
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
      {  j$ x( e2 a, y
  32. 1 N7 S- Y4 O3 D3 n, V# Q
  33. static int report_error( char *file, int line, char *call, int irc)# v. S! T  X; u1 b$ C9 C
  34. {
    ' G# e( A5 y6 U6 O+ P- p& x# N
  35.     if (irc)
    " _* e. H& D6 p$ g' ]
  36.     {
    $ v. m! \" k' N: d# R5 k
  37.         char err[133];
    5 U- v0 V' ~1 R! N) N

  38. 2 C( b- T3 e# |. G/ w2 ~
  39.         UF_get_fail_message(irc, err);
    ! K) |' E/ \: r" }# Y( u
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",% Q9 v* E; h+ [9 y' T: c4 i
  41.             irc, line, file);
    , M* V2 d3 G7 y% l7 _& `
  42.         ECHO("+++ %s\n", err);; V: b) h3 i7 ~) _! a9 A: k$ a% b7 g
  43.         ECHO("%s;\n", call);# v7 x, f, z: R) l  P3 R
  44.     }2 g0 \7 F) ?, X

  45. & c0 R1 M3 \3 [; `0 U8 E4 ]
  46.     return(irc);' T$ q  k, U* Q
  47. }# J5 d& n* U. E. a; ~) l* I

  48. + c" S& t2 K- c! N( H0 w2 Y" x
  49. 4 i7 l5 V$ y  ~5 y  j( {! H3 V
  50. static void do_it(void)
    6 V3 {% V5 g1 \) K/ O2 I
  51. {
    & k# O+ x6 Z% F7 e$ G
  52.     Session *theSession = Session::GetSession();
    3 S! r- p! g, D+ y6 O  d
  53.     Part *workPart(theSession->Parts()->Work());
    * W5 r% C" g6 F! b! C
  54.     Part *displayPart(theSession->Parts()->Display());
    ' C( O( U1 d' C/ ~
  55.     , z: e% a, D1 g3 d
  56.     PDM::SessionSettings *sessionSettings1;
    # b) v' _2 r7 F+ p. f
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();+ X7 D/ i. ^+ `$ S9 I- W0 S' Z
  58.       ~" q% ^6 K* o; Y
  59.     NXString CurrentGroup;3 F( X* L+ H# ]4 l3 l9 A) K7 Q
  60.     CurrentGroup = sessionSettings1->Group();
    % p5 K8 v5 h2 c2 T+ C8 w4 Z
  61.    
    / ]* {7 J9 U" l7 u" o" O
  62.     NXString CurrentRole;
    ) S7 y$ W+ W- \& v: u5 V
  63.     CurrentRole = sessionSettings1->Role();
      D. N% o+ M" T4 F  D6 y

  64. $ T- a- P* ~4 W9 k0 l- c
  65.     theSession->ListingWindow()->Open();
    ) w- C, q1 a1 ]9 {3 d' K% B& |
  66.    
    7 K- n. n7 ~/ u; o5 J; X
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");
    ' p; q$ x+ _: ?: Q5 w
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);
    ( S- L7 s/ u" G* d
  69.         - S8 O9 z) d' }9 E
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");   
    ( C" J& D8 j% v
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);+ L* d; n* z' i
  72. " V8 P0 a/ S7 f/ l6 a% }7 S
  73. }
    # T1 [5 B% d& _! @0 I8 P
  74. 3 o" H) `) l0 \. l! N
  75. /*ARGSUSED*/, w% I- o6 b$ \' G
  76. void ufusr(char *param, int *retcode, int paramLen)
    4 }  y0 X3 f. a# J4 E! A. R6 K
  77. {5 Z2 o5 J: Z+ `3 V% z2 `1 Q
  78.     if (UF_CALL(UF_initialize())) return;
    9 l* ]8 [5 S% s( ~2 `3 ^6 ]9 Y
  79.     do_it();- m6 ?+ n; Y0 y' }! y0 [/ i! x
  80.     UF_terminate();
    / x9 H3 X; J) m/ M' ]! w
  81. }1 X: w# v3 A  K. ^. N

  82. % I+ n0 o  C6 u& \: z& U
  83. int ufusr_ask_unload(void)
    # y$ h" n4 m/ O7 q1 j
  84. {0 K9 C& c; j; r8 \8 d6 \- d
  85.     return (UF_UNLOAD_IMMEDIATELY);- y% ~( r& j8 n1 d
  86. }* B0 I; [8 E9 P' G
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了