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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。, _- W) U: Q" g9 V

8 d: g9 ~( T: X0 G% ]" K
  1. #include <stdio.h>  ^! L) q% J+ P9 i* N, d$ ^) [2 s
  2. #include <string.h>2 K. x& r& W6 O5 @+ \2 D% P& _
  3. #include <uf.h>9 I& \7 j  M& t2 L1 ^$ n
  4. #include <uf_ui.h>
    / J& n) E3 i2 s' _2 r6 D6 [! W

  5. 0 [" A% [- w- [3 L- N
  6. #include <NXOpen/NXException.hxx>
    & k7 w: E2 K% n
  7. #include <NXOpen/Session.hxx>
    + B6 q7 l+ u- }$ d, z
  8. #include <NXOpen/ListingWindow.hxx>
    / O; [# k% K. n0 B) O: Q  O# \+ b! @
  9. #include <NXOpen/LogFile.hxx>
    5 t( c# D' O  A) Y
  10. #include <NXOpen/PDM_SessionSettings.hxx>0 \% Q1 u2 v/ v. e
  11. #include <NXOpen/Part.hxx>
    ( g$ |7 K, ]/ |/ x2 C( k: R/ R8 P& c7 V
  12. #include <NXOpen/ParTCollection.hxx>
    & U" q- I3 ~; j3 F0 F) p7 L
  13. #include <NXOpen/Session.hxx>: P; d. S/ T' M$ a  \6 q' U3 m
  14. : j* F! u6 \* k8 W. c; `
  15. using namespace NXOpen; // <== Very Important!2 Q9 P. O! z$ C* f. p4 p8 f

  16. 3 C+ S" a1 h" C: y2 o$ R
  17. #include <stdarg.h>, @6 c- v8 V+ v

  18. - \. V+ P% |8 E" g' k  g1 a- [
  19. static void ECHO(char *format, ...)
    9 O; {. B. t7 T8 y' e+ k, b8 W
  20. {- w+ q7 W7 `& \
  21.     char msg[UF_UI_MAX_STRING_LEN+1];4 e8 `7 W+ F6 q) n  l$ j& R% Q
  22.     va_list args;( i6 Z* G2 [- t# S4 D
  23.     va_start(args, format);
    - L4 _, M+ I/ N; D3 d' x( P
  24.     vsprintf(msg, format, args);
    4 V5 V) Q% l' P. a& w! ~
  25.     va_end(args);
    6 z0 k" j9 i( E4 u6 P6 {$ H3 E
  26.     UF_UI_open_listing_window();1 ~) ~. V' s, y) `0 y9 {, v
  27.     UF_UI_write_listing_window(msg);: L5 i2 p3 u; d
  28.     UF_print_syslog(msg, FALSE);; D; M+ n6 \2 s, F3 D
  29. }
    : {- @! J! P, U. k+ Z! f

  30. 6 _9 L3 [* x7 k  l2 _
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
    ( I7 v6 h  D# X. l. p( O

  32. 0 h2 ]+ r0 O  S5 A4 s
  33. static int report_error( char *file, int line, char *call, int irc)2 N* i4 F) V8 F' @; V, }7 A
  34. {
    9 w7 ?- }: L" Q$ n* o. x
  35.     if (irc)- A" v" c# Y3 M3 i
  36.     {
    / g/ I  V; `" t" Z' @
  37.         char err[133];
    4 @5 E  i- g- E( b

  38. ; D& h& K3 B8 y( y9 G+ [
  39.         UF_get_fail_message(irc, err);
    ! r! _9 y; G8 N; M* M$ L% J: C7 [
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",( v* A. I/ l& t- u$ E( Q1 @
  41.             irc, line, file);; P, S8 w7 u6 K8 A, a1 w
  42.         ECHO("+++ %s\n", err);# \8 i( m; Y  F+ E8 B3 O
  43.         ECHO("%s;\n", call);
    - V! _3 R& }4 B0 o3 _
  44.     }
    , t/ G& A% q( b. O

  45. 3 d0 S" ~' q) T% O$ u3 B
  46.     return(irc);
    # n7 d3 y8 Q; @9 ~5 \1 D/ _
  47. }) J- B% |  y* }1 d: b5 W
  48. 7 z5 q6 r0 m* f7 N; n: @% [' Q4 J

  49. 1 v1 H8 k3 F% y7 a% K" y
  50. static void do_it(void)
    " r  t% N, T7 J! N9 s& y% K
  51. {! X# F: p2 T5 s4 K0 ~
  52.     Session *theSession = Session::GetSession();( x+ H) k1 k  ~0 C( Q4 A+ W" R
  53.     Part *workPart(theSession->Parts()->Work());
    ! b* X+ N$ O# Q1 _0 E% J" ^. g
  54.     Part *displayPart(theSession->Parts()->Display());
    7 C$ {. y* {: ~4 n) H  d
  55.    
    ! x- Q+ u/ }1 f9 s3 V  x
  56.     PDM::SessionSettings *sessionSettings1;$ c& l; a6 e3 P, ?
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();0 I- J; ]1 s0 f; b+ W
  58.    
    $ ?) q6 b$ I0 {7 _
  59.     NXString CurrentGroup;
    6 Z; Q( v& ~( b# F$ \5 T' p
  60.     CurrentGroup = sessionSettings1->Group();, w3 `8 ?7 [; W8 t- c: i3 _
  61.     3 ~: b2 ^; q! X" Q, r( ^
  62.     NXString CurrentRole;* V! i/ P0 Z. S
  63.     CurrentRole = sessionSettings1->Role();
    ; ?( c0 K4 U! Y3 T8 E6 J/ f

  64. 9 d0 Y+ Y" u$ [9 y, p
  65.     theSession->ListingWindow()->Open();
    8 L; f* \3 v- l- P
  66.    
    ! r2 I, x' R7 l8 }
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");/ `, s  E! _5 [8 {5 S* ^% A  s* z
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);
    % v% {- w+ |6 M* n# b- u7 Q
  69.         7 S5 A: x+ M5 q
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");   
    0 S" P# I& g4 ]; c$ R2 R
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);
    # [# k3 ?1 U% B, _1 E" w
  72. 5 {; _, [4 w# v% n
  73. }
    9 V5 b; h+ A7 |( h* x2 F2 x4 I

  74. " N$ r# d1 H3 U$ a* H9 k& f9 K2 X
  75. /*ARGSUSED*/# |7 ]3 Y6 E* {# S
  76. void ufusr(char *param, int *retcode, int paramLen)
    3 I4 j% H  p9 _! l& K
  77. {. C* g& s: ?0 j
  78.     if (UF_CALL(UF_initialize())) return;; g! k1 C. L) C! _1 ~4 }1 R  t
  79.     do_it();$ _" t1 {. ~2 I# [" r) R
  80.     UF_terminate();+ _( V% e9 L; d! L/ R! E
  81. }
    6 _  x7 {# M8 v* F4 v- J. ?

  82. 2 x% Z# J  C  F& d( [
  83. int ufusr_ask_unload(void)
    8 g6 @( p5 e0 `# J& L% C' j
  84. {
    1 h6 t, C. N9 \0 e# X9 X( V
  85.     return (UF_UNLOAD_IMMEDIATELY);
    ; m- F0 Z: ]8 }$ P5 |6 m8 P+ r
  86. }
    8 x1 h* `, Z3 J7 k: I  A6 f
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了