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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。$ g& N* [' G* K1 A. S4 _
) ]* ~# z8 u" j) r
  1. #include <stdio.h>
    ' n2 s) v, g$ G
  2. #include <string.h>
    . P1 P! C8 w; a$ u! e2 Q
  3. #include <uf.h>; Z' k8 B- f3 _3 C1 d
  4. #include <uf_ui.h>8 k' A$ P# G4 ~+ Y6 ^, o

  5.   L8 ]; j9 z" c
  6. #include <NXOpen/NXException.hxx>
    ) @7 x. n( E# H4 |( ?. |- z' j
  7. #include <NXOpen/Session.hxx>
    $ f9 S* a4 b8 \, y1 C7 }
  8. #include <NXOpen/ListingWindow.hxx>
    % m8 J4 A( s- \( ?7 y9 r( c) B
  9. #include <NXOpen/LogFile.hxx>6 m% Y1 M1 Z, c  x: J
  10. #include <NXOpen/PDM_SessionSettings.hxx>7 u& \2 N! U: E% N, X1 {. ~4 X
  11. #include <NXOpen/Part.hxx>
    : g' M9 M4 u. \) V- k' i
  12. #include <NXOpen/ParTCollection.hxx>
    , q9 v+ K( E% T& ]9 U. O
  13. #include <NXOpen/Session.hxx>
    : @( F$ H  D/ m+ x# G. H9 }0 {
  14. 5 ^  X9 H0 T% S3 `8 S3 }2 |: l
  15. using namespace NXOpen; // <== Very Important!! I. a! b4 A) I8 z

  16. 7 w( A3 B" N/ B$ K% J+ q
  17. #include <stdarg.h>6 o9 x! Y' z4 Z& r" A7 A
  18. 9 a' b$ m5 g- E+ B7 P4 c& u
  19. static void ECHO(char *format, ...)
    0 ~7 L6 i1 ]6 \3 m7 D+ L
  20. {9 W' g0 [0 q2 n8 J/ Y  T
  21.     char msg[UF_UI_MAX_STRING_LEN+1];. R2 X0 P6 @" T7 k. _/ ]1 @1 T! C
  22.     va_list args;* F& m+ T4 p. W
  23.     va_start(args, format);
    / T$ M+ n9 I5 P" I" i- K
  24.     vsprintf(msg, format, args);
    1 V7 {' x$ V' G3 W0 l8 Q
  25.     va_end(args);
    ) x  f2 C: y4 t8 L5 r
  26.     UF_UI_open_listing_window();8 A/ j$ }1 g& Q- D' |( s3 f
  27.     UF_UI_write_listing_window(msg);) ^) L8 i% h( J( p
  28.     UF_print_syslog(msg, FALSE);# y& u4 \# [/ Z* Y6 P
  29. }  g* ]- b' H" B9 \' j2 q+ v

  30. ' t( O% S% K' z+ w' v6 ^; C# H
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
    # {$ N; y/ Y# X; A& M2 {
  32. 0 W  z; y* U9 O) A: i
  33. static int report_error( char *file, int line, char *call, int irc)
    0 N' L2 A+ R2 p; i+ X
  34. {
    - d* K* i* H, v
  35.     if (irc)
    5 Y2 ?4 |$ f  t
  36.     {
    & `( x. t  N# T# ?; a
  37.         char err[133];
    % X: M; o9 j+ z7 \2 @+ [' n
  38. ' j* C5 `/ [3 B1 c5 m5 Z
  39.         UF_get_fail_message(irc, err);4 m% X% e4 D1 u% _% h
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",7 S( d8 C' n' j4 o
  41.             irc, line, file);
    * |" w) u& |) A- B3 y
  42.         ECHO("+++ %s\n", err);
      Q1 a7 H9 ?% w# S2 _6 ^
  43.         ECHO("%s;\n", call);
    # u! ~+ u9 y0 J* z4 q
  44.     }
    2 O4 M" ^6 P3 K& I" X& I& P
  45. . l1 e& G# U7 b  i  |7 v2 f
  46.     return(irc);
    & ]1 r1 _* O8 V3 n) j
  47. }  }4 X2 V* ^0 M3 @  U
  48. ' c; n* F  d" f6 u5 f$ X: t$ o

  49. * @- e5 _4 k, }
  50. static void do_it(void)
    % D5 T  q9 r! T
  51. {! k7 m9 m- j  X' p4 j" ?0 E
  52.     Session *theSession = Session::GetSession();
    $ M9 w  Q& }# }3 V1 T
  53.     Part *workPart(theSession->Parts()->Work());
    : m6 {+ Y/ Q% L* c2 v& V9 x0 b  w
  54.     Part *displayPart(theSession->Parts()->Display());! T2 e  c6 R6 U6 @0 B
  55.     / a: p) W6 M. e" j1 H
  56.     PDM::SessionSettings *sessionSettings1;
    . U* `" w+ F: t6 g, K! F
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();
    % W0 R( i& I# J3 I6 C* p9 I( X0 {
  58.     3 ?5 o' H3 A, w/ S# ^- e5 x$ h! q
  59.     NXString CurrentGroup;
    / s& }# X( f0 c4 v
  60.     CurrentGroup = sessionSettings1->Group();
    ; f6 ?3 G: Z+ h
  61.    
    - D' s, ~$ ]7 ?* i7 T
  62.     NXString CurrentRole;
    + `* A* _2 i3 k& V/ K; \% F
  63.     CurrentRole = sessionSettings1->Role();
    - J% @. c/ j, F% n  _' f8 E

  64. 8 p  x& H9 j( k" @% t( j+ h
  65.     theSession->ListingWindow()->Open();7 e% z, r+ i" v' M* B6 R! N* M
  66.     6 H+ E3 ~. ?, B6 R0 Z
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");
    3 D( h/ U( \. k% p" p" O* n
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);
    8 R8 o# M! x, Z
  69.         & I0 C8 U7 {# c4 X4 s% M
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");   
    : a0 {& z# Y8 }1 }
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);
    / C$ n+ ?7 m  A
  72. 2 x9 ~- [; i  R( f8 H' o
  73. }7 L/ T2 C' D+ H% j% k
  74. - w: ^! m+ R+ F+ P6 n
  75. /*ARGSUSED*/* z0 \2 V5 m% q6 s+ m
  76. void ufusr(char *param, int *retcode, int paramLen), T5 g- F6 _6 a) |
  77. {, q9 O' {8 c" A8 q+ c
  78.     if (UF_CALL(UF_initialize())) return;
    # S3 n, U$ [' h& s" `" f
  79.     do_it();
    7 }. l- Y( p, E. v. u
  80.     UF_terminate();, q6 Q$ z; ~* q9 p' i; A! r2 u4 u, I$ g: X
  81. }
    * q- e7 ~0 j* w% G3 x0 \
  82. # H0 c( r/ y7 V& q4 z
  83. int ufusr_ask_unload(void)) [7 w6 b# b& @3 l% y/ c4 x
  84. {5 V9 f5 `$ u5 o4 B4 S
  85.     return (UF_UNLOAD_IMMEDIATELY);& e  P) u- R1 _# {+ A- I7 Q6 a
  86. }9 U& P) c; a! M7 M/ `
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了