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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。
( G' L/ M& Z3 g* u# K, D
. v+ j  E" F+ a* n& T5 I
  1. #include <stdio.h>
    ) p3 l7 r  d# `" y
  2. #include <string.h># S- f! s* G3 v1 ?, h% V( G
  3. #include <uf.h>5 @- }3 j/ P7 U/ J/ C5 G
  4. #include <uf_ui.h>
    ' z4 C" L" a; M5 U  G1 }  l$ @

  5. & n' W; `& j% W7 [6 M2 `  e5 S
  6. #include <NXOpen/NXException.hxx>
    - y/ A! W. f- t5 s7 k8 X- ?( s
  7. #include <NXOpen/Session.hxx>
    ( ]+ U, @. r( i, E6 Z. S% X
  8. #include <NXOpen/ListingWindow.hxx>
    3 b2 e. `! q9 e4 z2 x- S" s
  9. #include <NXOpen/LogFile.hxx>
    0 C0 {% O' g% v3 S; C, d
  10. #include <NXOpen/PDM_SessionSettings.hxx>
    : {1 A$ g. \) R  Y3 Z
  11. #include <NXOpen/Part.hxx>7 O$ v/ c8 ^: [1 g
  12. #include <NXOpen/ParTCollection.hxx>
    ) v3 U8 n- K' H" p( ]0 Y/ ?
  13. #include <NXOpen/Session.hxx># s7 c0 t* ?" p- ?; c0 [
  14. / Q+ V, N7 T5 Q( Q& w% B- @
  15. using namespace NXOpen; // <== Very Important!, l9 A; R) A# t, T  M, h$ ?

  16. 2 O9 m5 j' f0 N# w
  17. #include <stdarg.h>; S. s, j1 C2 x

  18. 2 G$ Z( c7 H; q+ O  ~; {
  19. static void ECHO(char *format, ...)
    ; Q6 G7 Q$ Y+ t$ w: Z
  20. {, ]' q( _% n8 ]! B
  21.     char msg[UF_UI_MAX_STRING_LEN+1];0 W3 B' E% G  @1 C
  22.     va_list args;% I; f7 |. y* Q- d! q
  23.     va_start(args, format);) H7 r5 Q5 t- L4 ^$ H8 D. M. c+ y# d
  24.     vsprintf(msg, format, args);- `( Y8 b# e2 o6 X8 e
  25.     va_end(args);
    " X1 z4 f, R/ r8 f8 j
  26.     UF_UI_open_listing_window();4 U" [; V# w  \! q
  27.     UF_UI_write_listing_window(msg);
    : C) a+ l$ r6 X
  28.     UF_print_syslog(msg, FALSE);
    % ~6 t+ s4 M1 l! d$ G
  29. }
    " _$ s2 d5 B9 z& ?: T1 S! u2 q' c

  30. - T4 l; U, Q) F2 ?# K
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))* B6 d" \3 E% c& u0 F# C

  32. - a: x! I* J$ s2 b$ b
  33. static int report_error( char *file, int line, char *call, int irc)
    & t) u0 e2 |  B+ o
  34. {! p4 f1 H- G- n; K, `" b
  35.     if (irc)
    2 S5 c4 ?0 G% L
  36.     {
    5 J" X) Y9 f; k' z7 ~
  37.         char err[133];
    1 ~& C/ f3 i0 [% F+ n" f" O+ M! {
  38. " p- n: h% J/ |, S; r
  39.         UF_get_fail_message(irc, err);6 c( Y9 Z8 h" @+ h$ P0 x/ u
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",7 x0 F3 g* E& U4 q9 J7 N0 h
  41.             irc, line, file);
    + ?. c/ ~  J5 X! V
  42.         ECHO("+++ %s\n", err);3 t0 i( S) k/ w; h* g2 H6 \; n
  43.         ECHO("%s;\n", call);% H+ C3 t  B" @& {# ?
  44.     }
    % Z( r( A4 B" c2 F3 q! V
  45. " ]& h/ O6 q1 D4 o! \# c! \
  46.     return(irc);
    , V: C5 Z! ?" y$ q; H; A/ C- ~$ l
  47. }
    ! W; Y8 ?; v* a

  48. * d' @2 h& l# e- T/ P

  49. 5 D+ m6 j- @# i# S- H- ?
  50. static void do_it(void)
    8 Z2 f3 I  l/ Q
  51. {
    ) E, ^  j1 [" ~
  52.     Session *theSession = Session::GetSession();
    3 k/ g5 B4 s5 G' F
  53.     Part *workPart(theSession->Parts()->Work());) [! m& o* w. n" Q( Y5 h  @/ I
  54.     Part *displayPart(theSession->Parts()->Display());
    ' i! v$ @. I6 ~' q
  55.    
    0 _: Q% C' V4 x0 s
  56.     PDM::SessionSettings *sessionSettings1;
    - M4 l+ i8 f# v0 B* ]
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();
    % A# ]& a$ p/ w# C& Q$ K
  58.     ' N1 E+ _: S3 i% Q
  59.     NXString CurrentGroup;* v1 T1 }9 W1 g" k+ K, S# O$ a2 N
  60.     CurrentGroup = sessionSettings1->Group();
    1 C0 I. R) R% o+ e
  61.    
    " J) ^7 h  s+ o" J5 @. T) [) Q, L- h
  62.     NXString CurrentRole;
      p# ^7 E/ P, h/ T9 |+ P" V
  63.     CurrentRole = sessionSettings1->Role();9 D/ u2 M  |5 d  z. L' Z. l

  64. - |" u, b* E; ]
  65.     theSession->ListingWindow()->Open();
    0 p' W5 B9 N7 T
  66.    
    + @7 |; K/ a3 S. B
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");
    - c# q/ y; g+ f" z8 E
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);0 `! T% X# k7 }
  69.         ) h, M  i9 v" K& e
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");   
    ' _9 S( M' X/ I1 l
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);2 k) e, r/ N$ z3 k- i$ y: }& f% w' Z

  72. ; H" i4 W% S! b" g( ?
  73. }
    % I# `! x- {) v/ u" g3 p
  74. ' V& G- Y$ u1 Y# E% K3 m
  75. /*ARGSUSED*/
    # V8 e* ]8 R# ~
  76. void ufusr(char *param, int *retcode, int paramLen)( G4 Z4 x& U3 i
  77. {
    : E' |) L7 k. F6 p0 o* p
  78.     if (UF_CALL(UF_initialize())) return;$ x5 G7 t) E( W+ `! V, H3 x
  79.     do_it();* r" J0 f, }- ~2 @7 P/ D6 i
  80.     UF_terminate();  o4 R; g' S" T) z  B/ L
  81. }  f0 l0 R! i2 r8 o6 d( F( _
  82. ( S& @2 B; D" {2 `0 b4 d! B+ o
  83. int ufusr_ask_unload(void)
    3 ~0 j3 ?/ `& V( k! n6 f
  84. {9 J2 V: d/ B. u0 S
  85.     return (UF_UNLOAD_IMMEDIATELY);% X% D& W# ^- B% Y1 E+ b: y8 z
  86. }
    - u: {7 I$ X1 O/ |( j& s
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了