|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
在集成环境中,NX和Teamcenter的集成中,获取当前用户的组group 和角色 role。# e9 I7 }% f& h% q( y) R6 T6 c
( o8 O, ~! f1 O0 t% ^
- #include <stdio.h>% y$ y1 M7 U' U! J9 `) B
- #include <string.h>: K; |! A3 _/ {, ]1 V4 Z
- #include <uf.h>
) N* t, a& V! ^1 p - #include <uf_ui.h>7 j! `! E1 c# O9 D S/ c7 O
- & b M6 i: A4 f# q+ U5 s
- #include <NXOpen/NXException.hxx>
9 G& j* J' p/ Q& ^4 }- m - #include <NXOpen/Session.hxx>6 j+ H- A3 q& u9 o2 U& [$ u
- #include <NXOpen/ListingWindow.hxx>: _5 ?* v, D( \+ L7 D5 k: c+ x! q7 L
- #include <NXOpen/LogFile.hxx> p: M7 i* |% P
- #include <NXOpen/PDM_SessionSettings.hxx>
! V; r9 w l' b7 \9 { - #include <NXOpen/Part.hxx>( p" \# J; `& D- ~' v; B# Z k
- #include <NXOpen/ParTCollection.hxx>
# M, }% S( x1 m" z! F$ @6 a) A - #include <NXOpen/Session.hxx>
' m. V1 `$ N: [
5 _7 V( U5 a( S; u' ]$ H7 O- using namespace NXOpen; // <== Very Important!
( g' Q7 U; y9 W! W9 d
2 h" Q9 [* ^0 J- #include <stdarg.h>
3 q( a, B3 b" @6 {; ?5 T& Q" @
! D! ^5 n7 A8 e8 ]. T- static void ECHO(char *format, ...)
3 Y9 U5 a& ~) o/ W( L - {3 Y0 @8 S& f% |! m5 x
- char msg[UF_UI_MAX_STRING_LEN+1];, `" e: ^$ m; T( Z. i
- va_list args;
7 i5 @$ k# b# t& g3 { Y - va_start(args, format);
9 E$ K5 r, E E$ b* N9 A6 A q - vsprintf(msg, format, args); v$ }+ b! G" Q% r6 ~+ i& l$ B
- va_end(args);0 [; f. I: l3 M" Y% X k" b" P1 `
- UF_UI_open_listing_window();0 w$ R5 g9 p/ h# j
- UF_UI_write_listing_window(msg);: l: |2 v* g4 u3 E# F0 i% y9 O6 _6 z
- UF_print_syslog(msg, FALSE);
, y, r" L: U1 ~' F2 s, V8 ~9 B! L) L* z - }
t4 G# Z7 d5 ?5 J4 o+ l
" r$ n/ b6 b& k* Y- #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))1 M9 g- z" U- I- q
4 O: K" i5 l( M8 `9 |- static int report_error( char *file, int line, char *call, int irc)
' _; q7 ~. ~5 F6 D! L: [ - { `! e0 |4 E, Z' W. Q6 m7 I9 {
- if (irc)
& q8 a3 y' h* z4 z) E - {
/ w# M6 {5 D* _ - char err[133];; a# p) S5 R8 @
- ' }4 s3 x" k& y5 h; z0 x
- UF_get_fail_message(irc, err);- o$ \/ `+ {: ?
- ECHO("*** ERROR code %d at line %d in %s:\n",/ ]6 I% J0 ]$ R% p3 E# z
- irc, line, file);0 J; W2 L- ~9 S( S
- ECHO("+++ %s\n", err);
9 J( L. ^+ W# X7 K4 s - ECHO("%s;\n", call);+ E4 V% Q% s$ H" f9 j" X
- }8 L' @0 e) }6 |# G$ l
- % O0 s" q9 g0 M! j- |
- return(irc);
9 r, Z6 M+ }- v# \" s! ]4 Q - }
7 y' e$ k* L U8 o, h% E
0 \# x8 A- _- H) R
& e" n8 {) D, Z- static void do_it(void)* b% Z, S, Y, C/ I! e% |
- {) E1 z' w( m: G6 J5 C( @9 O v
- Session *theSession = Session::GetSession();5 C, y) E& J! I! B1 F2 j0 x3 _0 t
- Part *workPart(theSession->Parts()->Work());
9 p3 M+ Y2 o n0 q' M* H0 h - Part *displayPart(theSession->Parts()->Display());
. L7 V; n. _# A( ^& c/ U3 X -
) ^1 k: h4 U( X6 T8 o - PDM::SessionSettings *sessionSettings1;
6 s7 Q* `8 Y6 b; P! Z, N1 T1 _; R - sessionSettings1 = theSession->NewDatabaseSessionOptions();% k* R" T! Y( C
-
6 b1 o3 E, v8 p3 ~ - NXString CurrentGroup;
a8 \/ N# Q5 {$ S - CurrentGroup = sessionSettings1->Group();
4 `$ G% X7 {, [ -
% p' B4 L% T s6 t/ {3 ? - NXString CurrentRole;; f" n) A" i% Z9 a H
- CurrentRole = sessionSettings1->Role();
/ X- ^$ q5 x! _; J0 A
4 F; ^! A/ x9 f" N- theSession->ListingWindow()->Open();5 A$ K$ `& H% j" {" S# y# X
- 8 z. M3 E6 B- D( \+ A
- theSession->ListingWindow()->WriteLine("Current Group: ");) D& f0 o U( D( F7 L: l/ \
- theSession->ListingWindow()->WriteLine(CurrentGroup);
8 l5 |$ X6 ~7 |* y+ Z) ] - 9 w- e5 x, _. q* _2 h
- theSession->ListingWindow()->WriteLine("Current Role: "); 3 M% r! `- s( Z4 ]: @9 [2 t1 Z
- theSession->ListingWindow()->WriteLine(CurrentRole);/ w% s/ J8 ^" p1 M
- * [; i* g' S% O: }5 B c
- }: i# U, _4 y4 S" o' @; h& j
% A! ]9 M" R) }! \- /*ARGSUSED*/
8 ^5 i$ K4 n! }) h% m - void ufusr(char *param, int *retcode, int paramLen)( k9 _8 p$ q/ O5 H. \
- {
y' |9 Y) |" [ {( v) K6 |7 ` - if (UF_CALL(UF_initialize())) return;
9 i2 N. D: p: M* \; C - do_it();5 [ M: K! h6 @* F' P, t
- UF_terminate();
& V% x7 f; O0 Y1 I7 A - }
8 y7 Z& V) I4 [) L, k
X6 T2 I) p" l% `7 r- int ufusr_ask_unload(void)1 a4 T$ Y2 e7 y( \
- {8 v& S" I' R' _8 T
- return (UF_UNLOAD_IMMEDIATELY);
+ C8 q' z, F- U$ E& E% j - }( M) I- l7 w( u6 u
复制代码 |
|