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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。; B9 c' H9 f* s- ^

+ U8 r4 t. ]& E  D+ z& a
  1. #include <stdio.h>8 S% Z- l2 C* F. o; r
  2. #include <string.h>. p: V3 C1 l/ P. J5 Z1 l, P
  3. #include <uf.h>
    0 e0 r1 o5 y: M
  4. #include <uf_ui.h>, p) @. ~& q- _9 K/ X( J+ K6 e

  5. # j# ~+ g1 O& s9 G0 K( ~1 ~4 c
  6. #include <NXOpen/NXException.hxx>
    - e1 o) x6 F. I7 M6 S
  7. #include <NXOpen/Session.hxx>
    $ l7 ^1 r+ f% i0 V$ ?0 k* }, S
  8. #include <NXOpen/ListingWindow.hxx>
    , x  C+ C6 g* o0 @( T$ q" w! v
  9. #include <NXOpen/LogFile.hxx>
    / L) l+ m' `  X0 R9 T0 q9 e
  10. #include <NXOpen/PDM_SessionSettings.hxx>
    4 C& {5 w" T* ^* }" E
  11. #include <NXOpen/Part.hxx>' w$ X2 C' v  Z: k' b/ I
  12. #include <NXOpen/ParTCollection.hxx>. F/ ~9 o5 ~- z8 c0 k# l* j7 M
  13. #include <NXOpen/Session.hxx>) V& ~6 w- w- [0 V. Q
  14. . _3 K8 j& k0 P6 v7 z) q6 Q- y
  15. using namespace NXOpen; // <== Very Important!
    & O; V9 I5 U9 p6 T- ^; k4 t
  16. : M4 o1 m% [1 {( O  H! A0 y7 _
  17. #include <stdarg.h>( N7 C" w( p6 J6 `8 s2 R" W
  18. 9 G+ k( N% h7 m& G( k- Z. a' c
  19. static void ECHO(char *format, ...)* ?( R6 _2 X8 d" V, u7 Z
  20. {
    & Y/ S  n: u3 h
  21.     char msg[UF_UI_MAX_STRING_LEN+1];
    * o8 B7 Y" C$ J1 x; S! `/ }
  22.     va_list args;) k' @, y! V  m
  23.     va_start(args, format);
    2 j, c0 k$ X1 J/ |' \- R& a( a
  24.     vsprintf(msg, format, args);9 Y2 Y6 U3 c' w$ `3 d
  25.     va_end(args);3 j3 k0 N& |- {# \! }. X! o
  26.     UF_UI_open_listing_window();
    " l. C  v- t2 U" w
  27.     UF_UI_write_listing_window(msg);
    ; Y. ^" `' b* e# e2 i
  28.     UF_print_syslog(msg, FALSE);: {8 ?6 l* R: i9 ?9 `: V
  29. }
    6 K6 H( L( y, k+ r- A0 j/ ?* B5 k
  30. & W1 r6 T+ u2 {6 d* ?! D% E9 s: K
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
      F4 @, w; E9 Q" U6 ~( c& W. D
  32. 6 o7 d0 L$ ~% J% |. H
  33. static int report_error( char *file, int line, char *call, int irc)& W& b# F6 Z6 m2 U- m5 b4 F
  34. {
    # e. W3 f0 ?6 J5 A9 Q( `8 R
  35.     if (irc)" [( X; ]8 J, T) H- H7 M/ B1 G4 L8 Z1 C
  36.     {
    5 y* a( ~4 N' k+ T; K
  37.         char err[133];
    2 J9 B7 H: n) g8 j+ i  C# S- h" A: T

  38. 6 v$ h8 C) ]" A
  39.         UF_get_fail_message(irc, err);; m& R- i. e$ [! O
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",
    * |# A3 A6 A" m" c
  41.             irc, line, file);
    0 u9 l: r9 m- c8 `7 G
  42.         ECHO("+++ %s\n", err);- f2 [' K, [+ ]! ?1 c
  43.         ECHO("%s;\n", call);$ s! ^( W: w$ Q/ K% [: L
  44.     }# W7 S% z8 k0 U- o0 }0 D7 q

  45. : o7 }4 d: U* {
  46.     return(irc);# a2 l2 \/ Z8 W3 J& s! A( x) F
  47. }
    ) V+ |3 d3 y8 J/ t

  48. % W  J8 w, B9 H
  49. : Q/ a9 X' U2 J8 i! E
  50. static void do_it(void)7 ?3 _3 x! O/ o4 w8 ?3 p& g
  51. {6 Y% D. R, G: V+ F
  52.     Session *theSession = Session::GetSession();
    : O* [3 f5 a$ g; {4 O8 B- o9 B( U
  53.     Part *workPart(theSession->Parts()->Work());% H6 Q# e: f, h5 ~
  54.     Part *displayPart(theSession->Parts()->Display());3 {; f8 x/ J  I8 O9 g0 S+ N
  55.    
    , ]4 N1 u! G& Y& _: T
  56.     PDM::SessionSettings *sessionSettings1;; e" N7 V9 [- ^0 O
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();# I3 @1 w4 i0 d+ F+ c8 y  K
  58.     . H' h$ V) E% d* @, ]' c4 ]
  59.     NXString CurrentGroup;, V5 ^( |: X2 T# X% Q
  60.     CurrentGroup = sessionSettings1->Group();
    , E3 s. @( H, T: l
  61.     ' L1 Y1 u. [) p) k1 W  [" K$ C
  62.     NXString CurrentRole;
    & D7 `7 m8 a2 G  B
  63.     CurrentRole = sessionSettings1->Role();$ I) O4 H- i! |1 X! ]! d7 @1 y
  64. 8 u- b4 h( R# i+ n
  65.     theSession->ListingWindow()->Open();
    7 X8 g9 {  a8 {. z
  66.     8 C4 m1 |) h7 \/ X+ J
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");
    * M1 ^! g# g0 G2 k+ P
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);9 |, }9 O8 C0 A7 o
  69.           n; w: F  g9 r. ^% b
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");    / q  ~7 k. p+ l) T
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);6 u6 n: |' J9 D) e) Q2 V2 P
  72. * k( E0 E  `2 z# s/ }7 @  Q- D- x
  73. }" G/ ]! W: u3 M- ]

  74. 1 |0 |: D7 G- {2 V
  75. /*ARGSUSED*/
    9 m4 l6 M- R" l9 _
  76. void ufusr(char *param, int *retcode, int paramLen)
    ! @0 I! y0 N6 `+ X, G, j0 y
  77. {
    ) I6 F1 {. _$ p) D% e, n
  78.     if (UF_CALL(UF_initialize())) return;9 J! l; Q/ n7 h. |$ d% D! D
  79.     do_it();
    & |4 H; w4 U0 g9 E6 P0 m
  80.     UF_terminate();0 R- `: O: M" X# s. n$ L9 o: p
  81. }+ Q. |4 O1 D) T9 Z
  82. ; R8 {; [+ m. M3 Q- i$ k$ a
  83. int ufusr_ask_unload(void)- j+ @% I% P1 t7 {* E
  84. {
    * C0 i4 C0 w9 W8 `, b7 L) ?/ d* [, ~* ^
  85.     return (UF_UNLOAD_IMMEDIATELY);
    ; W, q3 P8 K# j; y* S
  86. }( W* o3 H& P1 \1 w/ M! \! \4 h
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了