|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
在集成环境中,NX和Teamcenter的集成中,获取当前用户的组group 和角色 role。
) m. ]- b* {6 T( ~" G# {2 R1 s
, C* R, c2 j1 w3 v4 ?% a- #include <stdio.h>
E# L2 T9 p% Q - #include <string.h>
% U" j. M6 n3 k0 R - #include <uf.h>7 v% B$ e7 @5 o
- #include <uf_ui.h>. t! `& g4 }7 h! t* \" X+ H( J
5 U3 t% M5 v2 t6 Z1 y- #include <NXOpen/NXException.hxx>
- t$ H! ^$ E" d& X3 g% h; p0 T - #include <NXOpen/Session.hxx>& k* A- P; ]. b1 e* Y, L
- #include <NXOpen/ListingWindow.hxx>
( R( Q' E% ^9 P- \ - #include <NXOpen/LogFile.hxx>
1 T8 Y* O2 K. \: j$ P, j; c( `4 y6 R - #include <NXOpen/PDM_SessionSettings.hxx>
R$ i4 `- X+ G2 P+ D# ` J* e - #include <NXOpen/Part.hxx>$ c% y" [* S. `- F
- #include <NXOpen/ParTCollection.hxx>( k# K/ o) M* n7 D
- #include <NXOpen/Session.hxx>
- l3 o8 r, W% S3 C* M# a- X
+ k6 R/ Q$ h5 [( U( B' n5 Z, A9 ?! J- using namespace NXOpen; // <== Very Important!% ]6 I" h: k$ `- p# E# g" V. m
- % {$ w% J. T/ Z2 S8 u
- #include <stdarg.h>
& Q0 @. R3 |0 z. E - 2 j: Z. N' m) J- G, t
- static void ECHO(char *format, ...)3 i" n2 N4 `% H" q$ g
- {( ^# s" s9 ^2 N) e# c
- char msg[UF_UI_MAX_STRING_LEN+1];
k4 k V( x+ a - va_list args;( R+ N* D2 M# _( v$ b0 }# L# t
- va_start(args, format);
3 s- H( n4 Q4 D% V - vsprintf(msg, format, args);
$ b, D& O3 G, w; f, j - va_end(args);; I; E! j$ |8 ~0 Y! A4 G- ^2 W6 {3 H
- UF_UI_open_listing_window();
5 [ g7 W6 O, X4 g/ { - UF_UI_write_listing_window(msg);% _5 u6 m) J$ ]# r% O6 S) G
- UF_print_syslog(msg, FALSE);
( A1 x: o: u5 h! A. i - }
( Y* E6 [" t, k9 |+ ]6 V
y% T6 F% w0 X7 t- #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
5 ]% {8 L; H. V
7 b. d; t; f% R$ g+ O- static int report_error( char *file, int line, char *call, int irc)9 f0 U2 r8 ?* g; M
- {- C, I Q7 m( J, \9 _
- if (irc)
) k1 T3 R8 C% z5 j1 N7 s- q* a - {
+ |+ Z5 q* l& S, \0 r z) \5 q a - char err[133];& A* B/ t5 c7 U, J x$ s" u
- 6 m5 s# s+ E6 H+ }# ?9 w2 b
- UF_get_fail_message(irc, err);
$ v. n$ \+ b, g$ d - ECHO("*** ERROR code %d at line %d in %s:\n",/ @( |7 v; C3 u2 f: o# ~
- irc, line, file);- A+ V& G4 x2 F( V9 i
- ECHO("+++ %s\n", err);) Y6 A, H5 f7 O3 E, s9 b
- ECHO("%s;\n", call);
1 Z1 `# T8 ?& c! i - }# X! }& l9 i+ v+ v5 D& f
- 9 i% h( C8 r; F" B8 X1 w- p2 A
- return(irc);
' D7 s$ j& c9 d5 V! ?& U* e - }
7 \* Z: H, _0 k0 ^" j @/ [+ U
3 \. n, i% ` ^, G% I/ [# l8 A
: g( o, ~3 f( s+ L- static void do_it(void)
+ _# K5 n, v+ U3 d- w3 @% B - {
2 c @) }' _ R3 ?1 \! w - Session *theSession = Session::GetSession();7 g8 i8 R9 O: l! [) Q" Y# v
- Part *workPart(theSession->Parts()->Work());, [3 E7 [2 D. a! _
- Part *displayPart(theSession->Parts()->Display());
. O3 _; ?" l! \; C6 C9 S - % e5 m+ J+ Y. U% [9 ^ A
- PDM::SessionSettings *sessionSettings1;
1 M! S! A$ t$ f9 k0 O4 D3 b- I! ` - sessionSettings1 = theSession->NewDatabaseSessionOptions();
# X/ F/ @& Q, N" D W) _; I9 j - ; i! V* ^) o, j1 t% w
- NXString CurrentGroup;
$ o/ q, k9 n6 G# L4 |: X8 C; ?5 i - CurrentGroup = sessionSettings1->Group();! W$ s) ]+ y; X# J" A9 V0 F; z
-
" F3 S, P- t3 j3 K$ l9 e- ^ - NXString CurrentRole;+ T* j$ ^! P1 P. I, |" P& z
- CurrentRole = sessionSettings1->Role();
0 u0 w" b8 U: B+ [ - 9 w9 @9 M% m4 a/ n& m( N
- theSession->ListingWindow()->Open();
3 w6 j$ K7 r$ @$ W; c - + C7 O7 z b6 b: f3 n- F' a" i
- theSession->ListingWindow()->WriteLine("Current Group: ");' L) ?( ]; j) v
- theSession->ListingWindow()->WriteLine(CurrentGroup); I% `% a) ~8 F" u
- ( U. x8 g4 x4 l! u1 G# {' l6 a
- theSession->ListingWindow()->WriteLine("Current Role: "); ! l, S8 D7 p! [" }: o- M5 U
- theSession->ListingWindow()->WriteLine(CurrentRole);
1 ~) V2 ?# _- L. {4 {
$ k A. m2 o1 `9 o0 U- }
. T# G5 I2 V& _ - ' j8 U9 K9 D, j" t
- /*ARGSUSED*/4 G5 g; l2 b# Y d9 h5 N/ U! }
- void ufusr(char *param, int *retcode, int paramLen)
3 G; P8 ?$ ~6 u \3 x O0 d - {0 L( u: }/ _* n5 G8 v/ T3 ^. u
- if (UF_CALL(UF_initialize())) return;0 _$ ~$ C! \! p, a& c2 o
- do_it();
0 D5 l) }9 F5 g x - UF_terminate();6 W' D! n$ M' N1 \3 C( g
- }
2 y: Q; Q! C4 g7 f. I
+ [5 {3 u' `6 v- int ufusr_ask_unload(void)
, T( _5 U! M6 K' S - {! W0 R, D# j, I! M j
- return (UF_UNLOAD_IMMEDIATELY);
! P) D! R7 ]- S7 ^# S( V: o4 d - }, i. W' k4 U' O9 C/ s6 e
复制代码 |
|