|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
在集成环境中,NX和Teamcenter的集成中,获取当前用户的组group 和角色 role。
( E5 T' g% H4 Q @- p( F. x. G" X, v8 }& J; \% X
- #include <stdio.h>' Z9 V' H( ]7 b8 B
- #include <string.h>0 M D( n. R+ k2 a3 ^% H0 R2 |+ n
- #include <uf.h>' h T8 `) i! y
- #include <uf_ui.h>
9 ?8 Y2 y L2 E- `. B8 L: b
6 q2 R( r! d+ `3 w5 s- #include <NXOpen/NXException.hxx>, }9 q5 N3 h; i+ b" |
- #include <NXOpen/Session.hxx>
. W/ M; p8 k# C2 [0 O* t5 g - #include <NXOpen/ListingWindow.hxx>& k3 ^) i. l7 N: L
- #include <NXOpen/LogFile.hxx>
; `7 [& b$ b" h# [2 F - #include <NXOpen/PDM_SessionSettings.hxx>- Y8 i! ]- g i; V# p4 x2 H; i( w
- #include <NXOpen/Part.hxx>7 t9 G( O2 k# l) b: T! [
- #include <NXOpen/ParTCollection.hxx>
% o+ L& `) ^6 j% s! ^! M& w S - #include <NXOpen/Session.hxx>4 X+ X, X* B8 v. L$ k9 O
4 U1 \0 b! }6 c- using namespace NXOpen; // <== Very Important!* Y! b$ M% I: a$ @7 m7 R. b0 t
$ q' n7 ~6 l$ ^/ s+ |9 `- #include <stdarg.h>
8 T( w: Y/ O$ f$ y3 d% X - ) ~4 C7 j& S" {9 w& M1 \% Q- K: q
- static void ECHO(char *format, ...)
# m% p& @) y) ] y. P - {0 Z" N- w9 v) S( Q
- char msg[UF_UI_MAX_STRING_LEN+1];8 C9 \+ f: A8 F7 R8 y$ H U2 ^& d2 J2 _
- va_list args;
/ i6 o, F5 [+ k - va_start(args, format);
R; l) U7 N. x, @1 F" L- p - vsprintf(msg, format, args);9 P2 n- x0 q" }# h# {
- va_end(args);) S' E6 d% r( C0 ? }( _: p$ A, k; q
- UF_UI_open_listing_window();
$ f4 @9 [0 R' W e0 M - UF_UI_write_listing_window(msg);
! \& m; B% k3 N4 K - UF_print_syslog(msg, FALSE);( m" j( x7 j6 E% Z# P7 a4 I( k; P5 g( C
- }; f7 M0 k: k4 M( P+ X, Z; ]
- 0 G+ j8 n. k R6 M- d8 L& }
- #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))0 ~( R0 l+ W' p* U, C0 D) ~. v
# H4 d3 b9 b& O' {- static int report_error( char *file, int line, char *call, int irc)5 F. r- N8 h6 ^# A' n0 y
- {6 h* H% v9 w( y# a7 A* y
- if (irc)/ k# ]/ O" k- N6 ]$ z4 u% V0 Z
- {& }4 D7 M4 k* ^
- char err[133];/ D0 r, g" a) @2 F+ p8 ~2 k# W
! p6 d9 K7 }: S- ~0 b- a: E) t- UF_get_fail_message(irc, err);
G" [- Q5 y$ e6 w8 O2 Y; P0 H" G - ECHO("*** ERROR code %d at line %d in %s:\n",
3 {) ^6 Y3 ^3 ^- T! i; {9 Z - irc, line, file);' W$ c$ U- s) w$ f- Z) ?6 ?* S
- ECHO("+++ %s\n", err);
& O4 _: x+ N/ C A - ECHO("%s;\n", call);
) j8 R3 |6 q$ P0 \; D4 R - }% _9 w& N# }& @* K7 T
- 6 w1 R5 x: L+ \9 S) k1 A
- return(irc);
/ K. a! O# N g4 Q - }$ ?* h9 k; v8 P) j% S9 T) B
- 3 K7 |. [5 a! `+ G! A1 h. O: f' ]( l
$ ~; @; s( g+ j! n* x3 }- static void do_it(void)
7 p6 l3 `6 g4 p7 w/ H( ^ - {) O, w- r; q4 B/ I+ K5 I
- Session *theSession = Session::GetSession();
( `* z/ {) j5 H - Part *workPart(theSession->Parts()->Work());
: Y1 b2 y6 R% |) I: Z, o - Part *displayPart(theSession->Parts()->Display());4 Q0 n5 C7 c% V1 E1 s9 j
- ( T6 f, O, v6 h) |' e: Z0 Y) D
- PDM::SessionSettings *sessionSettings1;
+ r" [( j8 y- E. y# G - sessionSettings1 = theSession->NewDatabaseSessionOptions();0 k; M0 n' t0 f
- # h5 ~* a- {* r1 S
- NXString CurrentGroup;
& H1 P( B& ~7 q+ ?4 k6 |! ^ - CurrentGroup = sessionSettings1->Group();# { X5 M) u z8 t- l
- : s9 Z: K( _& M- g/ r2 I& n! S d
- NXString CurrentRole;
% Z% S% k6 O1 d5 M0 W+ j - CurrentRole = sessionSettings1->Role();
+ s% d" @" v) v+ j+ R - 9 j; _2 Q5 E* O5 I) ]1 B# s
- theSession->ListingWindow()->Open();
- F7 W9 k4 l. G/ ] - `' O2 z' x s+ B
- theSession->ListingWindow()->WriteLine("Current Group: ");
N* V" T1 [, ]1 ]! v- p - theSession->ListingWindow()->WriteLine(CurrentGroup);9 [# `/ N0 k% e3 H5 j6 u& h
- ; ~- y1 O# X* q7 f9 A! y4 E9 r
- theSession->ListingWindow()->WriteLine("Current Role: "); 4 _. W( z* n: K" p' o) U
- theSession->ListingWindow()->WriteLine(CurrentRole);
5 t. W+ D& M x M - 5 [+ o; k1 Q- X7 W, w
- }
- o" F7 e0 g. b - : B0 }3 K, Q6 \5 j' N
- /*ARGSUSED*/
7 H6 r1 I9 [; {( ^ - void ufusr(char *param, int *retcode, int paramLen) ]6 Z/ j: E3 x
- {
2 ]' ?# l1 S# R$ E9 d1 Y - if (UF_CALL(UF_initialize())) return;
& d& S( v2 a) F/ ^3 v3 h - do_it();
( `: W0 ^" U$ d" Z) j9 U - UF_terminate();
0 o! o3 B: G* h - }) x4 q" V4 ~! i* V ~/ e) W1 K) [
- ' J2 x4 U, |9 D& s- C$ w5 O
- int ufusr_ask_unload(void)
. s" F- t) e W9 D% E- d - {
- D. c9 C/ ^8 r+ j - return (UF_UNLOAD_IMMEDIATELY);2 a. f, t# m. u: T8 x" A! Z
- }
b" h6 x' w' U- r
复制代码 |
|