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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。
) m. ]- b* {6 T( ~" G# {2 R1 s
, C* R, c2 j1 w3 v4 ?% a
  1. #include <stdio.h>
      E# L2 T9 p% Q
  2. #include <string.h>
    % U" j. M6 n3 k0 R
  3. #include <uf.h>7 v% B$ e7 @5 o
  4. #include <uf_ui.h>. t! `& g4 }7 h! t* \" X+ H( J

  5. 5 U3 t% M5 v2 t6 Z1 y
  6. #include <NXOpen/NXException.hxx>
    - t$ H! ^$ E" d& X3 g% h; p0 T
  7. #include <NXOpen/Session.hxx>& k* A- P; ]. b1 e* Y, L
  8. #include <NXOpen/ListingWindow.hxx>
    ( R( Q' E% ^9 P- \
  9. #include <NXOpen/LogFile.hxx>
    1 T8 Y* O2 K. \: j$ P, j; c( `4 y6 R
  10. #include <NXOpen/PDM_SessionSettings.hxx>
      R$ i4 `- X+ G2 P+ D# `  J* e
  11. #include <NXOpen/Part.hxx>$ c% y" [* S. `- F
  12. #include <NXOpen/ParTCollection.hxx>( k# K/ o) M* n7 D
  13. #include <NXOpen/Session.hxx>
    - l3 o8 r, W% S3 C* M# a- X

  14. + k6 R/ Q$ h5 [( U( B' n5 Z, A9 ?! J
  15. using namespace NXOpen; // <== Very Important!% ]6 I" h: k$ `- p# E# g" V. m
  16. % {$ w% J. T/ Z2 S8 u
  17. #include <stdarg.h>
    & Q0 @. R3 |0 z. E
  18. 2 j: Z. N' m) J- G, t
  19. static void ECHO(char *format, ...)3 i" n2 N4 `% H" q$ g
  20. {( ^# s" s9 ^2 N) e# c
  21.     char msg[UF_UI_MAX_STRING_LEN+1];
      k4 k  V( x+ a
  22.     va_list args;( R+ N* D2 M# _( v$ b0 }# L# t
  23.     va_start(args, format);
    3 s- H( n4 Q4 D% V
  24.     vsprintf(msg, format, args);
    $ b, D& O3 G, w; f, j
  25.     va_end(args);; I; E! j$ |8 ~0 Y! A4 G- ^2 W6 {3 H
  26.     UF_UI_open_listing_window();
    5 [  g7 W6 O, X4 g/ {
  27.     UF_UI_write_listing_window(msg);% _5 u6 m) J$ ]# r% O6 S) G
  28.     UF_print_syslog(msg, FALSE);
    ( A1 x: o: u5 h! A. i
  29. }
    ( Y* E6 [" t, k9 |+ ]6 V

  30.   y% T6 F% w0 X7 t
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
    5 ]% {8 L; H. V

  32. 7 b. d; t; f% R$ g+ O
  33. static int report_error( char *file, int line, char *call, int irc)9 f0 U2 r8 ?* g; M
  34. {- C, I  Q7 m( J, \9 _
  35.     if (irc)
    ) k1 T3 R8 C% z5 j1 N7 s- q* a
  36.     {
    + |+ Z5 q* l& S, \0 r  z) \5 q  a
  37.         char err[133];& A* B/ t5 c7 U, J  x$ s" u
  38. 6 m5 s# s+ E6 H+ }# ?9 w2 b
  39.         UF_get_fail_message(irc, err);
    $ v. n$ \+ b, g$ d
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",/ @( |7 v; C3 u2 f: o# ~
  41.             irc, line, file);- A+ V& G4 x2 F( V9 i
  42.         ECHO("+++ %s\n", err);) Y6 A, H5 f7 O3 E, s9 b
  43.         ECHO("%s;\n", call);
    1 Z1 `# T8 ?& c! i
  44.     }# X! }& l9 i+ v+ v5 D& f
  45. 9 i% h( C8 r; F" B8 X1 w- p2 A
  46.     return(irc);
    ' D7 s$ j& c9 d5 V! ?& U* e
  47. }
    7 \* Z: H, _0 k0 ^" j  @/ [+ U

  48. 3 \. n, i% `  ^, G% I/ [# l8 A

  49. : g( o, ~3 f( s+ L
  50. static void do_it(void)
    + _# K5 n, v+ U3 d- w3 @% B
  51. {
    2 c  @) }' _  R3 ?1 \! w
  52.     Session *theSession = Session::GetSession();7 g8 i8 R9 O: l! [) Q" Y# v
  53.     Part *workPart(theSession->Parts()->Work());, [3 E7 [2 D. a! _
  54.     Part *displayPart(theSession->Parts()->Display());
    . O3 _; ?" l! \; C6 C9 S
  55.     % e5 m+ J+ Y. U% [9 ^  A
  56.     PDM::SessionSettings *sessionSettings1;
    1 M! S! A$ t$ f9 k0 O4 D3 b- I! `
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();
    # X/ F/ @& Q, N" D  W) _; I9 j
  58.     ; i! V* ^) o, j1 t% w
  59.     NXString CurrentGroup;
    $ o/ q, k9 n6 G# L4 |: X8 C; ?5 i
  60.     CurrentGroup = sessionSettings1->Group();! W$ s) ]+ y; X# J" A9 V0 F; z
  61.    
    " F3 S, P- t3 j3 K$ l9 e- ^
  62.     NXString CurrentRole;+ T* j$ ^! P1 P. I, |" P& z
  63.     CurrentRole = sessionSettings1->Role();
    0 u0 w" b8 U: B+ [
  64. 9 w9 @9 M% m4 a/ n& m( N
  65.     theSession->ListingWindow()->Open();
    3 w6 j$ K7 r$ @$ W; c
  66.     + C7 O7 z  b6 b: f3 n- F' a" i
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");' L) ?( ]; j) v
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);  I% `% a) ~8 F" u
  69.         ( U. x8 g4 x4 l! u1 G# {' l6 a
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");    ! l, S8 D7 p! [" }: o- M5 U
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);
    1 ~) V2 ?# _- L. {4 {

  72. $ k  A. m2 o1 `9 o0 U
  73. }
    . T# G5 I2 V& _
  74. ' j8 U9 K9 D, j" t
  75. /*ARGSUSED*/4 G5 g; l2 b# Y  d9 h5 N/ U! }
  76. void ufusr(char *param, int *retcode, int paramLen)
    3 G; P8 ?$ ~6 u  \3 x  O0 d
  77. {0 L( u: }/ _* n5 G8 v/ T3 ^. u
  78.     if (UF_CALL(UF_initialize())) return;0 _$ ~$ C! \! p, a& c2 o
  79.     do_it();
    0 D5 l) }9 F5 g  x
  80.     UF_terminate();6 W' D! n$ M' N1 \3 C( g
  81. }
    2 y: Q; Q! C4 g7 f. I

  82. + [5 {3 u' `6 v
  83. int ufusr_ask_unload(void)
    , T( _5 U! M6 K' S
  84. {! W0 R, D# j, I! M  j
  85.     return (UF_UNLOAD_IMMEDIATELY);
    ! P) D! R7 ]- S7 ^# S( V: o4 d
  86. }, i. W' k4 U' O9 C/ s6 e
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了