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

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

  [复制链接]

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

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

admin 楼主

2013-11-6 19:00:16

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

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

x
在集成环境中,NXTeamcenter的集成中,获取当前用户的组group 和角色 role。& E, K$ L0 v% c# u9 J
  P: m8 j1 `; B2 ^
  1. #include <stdio.h>: d8 q4 l4 D. K/ d8 g# m/ ]
  2. #include <string.h>, A: o! t% L7 N: i5 x( O  l
  3. #include <uf.h>5 a, r- I4 r9 E' Y
  4. #include <uf_ui.h>4 \2 k( [7 c1 l, z
  5. : F; h3 s1 l- p# S+ m+ p9 O
  6. #include <NXOpen/NXException.hxx>$ U( M2 E1 x' v! E! ~
  7. #include <NXOpen/Session.hxx>! i- G0 ^- b9 W* z) S* ^" t) s8 f
  8. #include <NXOpen/ListingWindow.hxx>! D& C! J% Z5 {- Z# o2 I
  9. #include <NXOpen/LogFile.hxx>- H7 D  e9 g! j
  10. #include <NXOpen/PDM_SessionSettings.hxx>" Q  e" v' d; C/ [8 d
  11. #include <NXOpen/Part.hxx>
    5 M9 t5 Q6 J" n% U# }6 z& D
  12. #include <NXOpen/ParTCollection.hxx>
    $ D$ Z+ Z5 A. l% {
  13. #include <NXOpen/Session.hxx>
    " k; g8 z0 R2 E' f! m! o7 x

  14. 9 d; |6 k; Y7 _1 p0 x8 T+ e' b
  15. using namespace NXOpen; // <== Very Important!9 s& [2 {. T  S6 `" ?$ S  W; A

  16. 3 h" b& e- F# h7 g
  17. #include <stdarg.h>
    - v! r* ^+ I2 f, |* f1 ]- N

  18. 7 y3 v! V: }( w8 G7 A
  19. static void ECHO(char *format, ...)5 Z% t: O% {# e5 j- @0 l. D  D
  20. {7 v7 j: u! j) O3 s# p7 ^7 n
  21.     char msg[UF_UI_MAX_STRING_LEN+1];
    ( M( P& [: I' W' t! p# ?- j
  22.     va_list args;
    & G4 X9 H7 [2 I7 z' H: _
  23.     va_start(args, format);
    & {0 c4 H, {( [9 f0 ?% W7 B) W
  24.     vsprintf(msg, format, args);2 i4 A5 w1 R1 L5 W2 G3 c
  25.     va_end(args);
    & B, Y3 t7 P7 N- U
  26.     UF_UI_open_listing_window();  q. Y0 i* O: J4 L) i
  27.     UF_UI_write_listing_window(msg);7 o. f# n. N, W* u
  28.     UF_print_syslog(msg, FALSE);
    % D+ s$ K7 k+ M4 R
  29. }
      h! N" g6 ^2 ?* r* R$ J+ j) C

  30. ; Q1 B# ^) N. _$ ^: R
  31. #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X))). j0 e- k$ {' O7 c. l# Z3 }

  32. 8 _$ l+ c7 }7 Y/ T. z
  33. static int report_error( char *file, int line, char *call, int irc)
    + [2 Y3 Z3 _6 s" x9 _
  34. {
    * M# T# P$ `- T: t9 i# a
  35.     if (irc)! u6 I- f1 E" h0 w, y
  36.     {
    4 }! u6 \: K  Q, _0 C& a0 A
  37.         char err[133];
    % k- h- s9 D0 M% t  |* m

  38. % `1 d6 d3 ]' A
  39.         UF_get_fail_message(irc, err);
    $ \$ c+ M9 C- F! a, ^1 D, ^
  40.         ECHO("*** ERROR code %d at line %d in %s:\n",
    ! {) B) C$ }& \# g. T! s
  41.             irc, line, file);
    / V$ o- |4 {% C4 m
  42.         ECHO("+++ %s\n", err);
    1 l$ w- R( e1 o# C0 b
  43.         ECHO("%s;\n", call);8 z4 X6 _; u/ }+ p# ^  u$ Q
  44.     }+ r3 r2 `5 n) H7 E' o6 G
  45. 0 W( U* C3 u0 c/ z# J+ _
  46.     return(irc);4 C( h( C+ e/ y! d' e/ r% C
  47. }
    . h5 i" d! `* V
  48. 5 {" [+ K' v5 ~, V( k3 f
  49. # Y5 [" N2 S/ I. X
  50. static void do_it(void)3 s* N- E  T( t: ^: A% s
  51. {& J/ o( X: h( |( Y
  52.     Session *theSession = Session::GetSession();: ~/ v4 C; _# R5 o( e2 p' ?* b+ I
  53.     Part *workPart(theSession->Parts()->Work());% a# y( a' q! W5 E0 F- t' b* ?6 I
  54.     Part *displayPart(theSession->Parts()->Display());
    5 @  l  G8 K0 R6 Z* `" t
  55.     $ G% _4 m8 R6 E) v
  56.     PDM::SessionSettings *sessionSettings1;) A8 T# ]3 T4 D, j
  57.     sessionSettings1 = theSession->NewDatabaseSessionOptions();
    ! `) [  c0 s' y& ~
  58.    
    ' ?  G3 G, x$ o/ t$ A* ?. k
  59.     NXString CurrentGroup;: w2 x; Q2 Q3 D4 c6 d" W
  60.     CurrentGroup = sessionSettings1->Group();
    / s1 y5 ?' r' R- D; ?4 p6 n9 V$ G
  61.     : ]1 l0 ?3 @; l" Y
  62.     NXString CurrentRole;
    4 Q/ k9 k3 Z  V( t9 P3 F- v
  63.     CurrentRole = sessionSettings1->Role();$ c6 L, j% G8 S
  64. 6 }# [4 M, f* p" \" b/ J. ^
  65.     theSession->ListingWindow()->Open();
    3 c6 F1 w: e  Z) A4 P$ z! V
  66.     6 w  ?/ d' z9 Z' Z- U
  67.     theSession->ListingWindow()->WriteLine("Current Group: ");( E: D! w* d$ X4 u: G+ J$ d# m: I
  68.     theSession->ListingWindow()->WriteLine(CurrentGroup);
    4 k8 i6 }7 `8 {0 U- R# F. |( q) R; D: T
  69.         7 X0 j8 p) ^# q& |8 r8 w
  70.     theSession->ListingWindow()->WriteLine("Current Role: ");   
    1 J/ O  m+ V7 d8 W! D! q
  71.     theSession->ListingWindow()->WriteLine(CurrentRole);9 C5 F. ?" }3 x, L. ]/ C% i0 ]5 ?

  72. 7 y& x9 w, A" ~% h
  73. }
    * @0 n7 g" H9 c; s

  74. . n5 j  F; V) @
  75. /*ARGSUSED*/  g5 V0 q6 ]& y
  76. void ufusr(char *param, int *retcode, int paramLen)
    & b: T( I2 A# x$ ?- _
  77. {
    9 \9 t" J( m- Q
  78.     if (UF_CALL(UF_initialize())) return;
    $ G, \# z5 i7 }& f: b
  79.     do_it();+ y0 b4 n8 Y9 p3 C# r1 T
  80.     UF_terminate();
    3 L$ @2 f$ ~. \1 f; r+ Q2 Q0 [
  81. }: e! X( N; S0 _% V% B8 J2 `

  82. 8 x- ~/ w: L3 U, J
  83. int ufusr_ask_unload(void)
    5 @1 c6 y+ [; |
  84. {1 v  l+ o: I: @2 r/ a% @
  85.     return (UF_UNLOAD_IMMEDIATELY);. h5 A5 q, s+ a+ C
  86. }
    ; T/ A1 k0 H- |. n3 ~6 g
复制代码
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了