|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
在集成环境中,NX和Teamcenter的集成中,获取当前用户的组group 和角色 role。% Y6 q/ b0 V! s2 T- G
5 w( w( O0 M" j4 R
- #include <stdio.h>
. [$ b: S/ L$ ~: U ~3 H - #include <string.h>
* a; A1 g9 w$ l- g1 P, G7 T; S - #include <uf.h>
" B$ C( P' b6 H4 b6 C& z( P7 W - #include <uf_ui.h>( R4 L/ Z# B1 O& s: X+ O
- ! F$ @3 [2 G) K) K+ ^) b8 f
- #include <NXOpen/NXException.hxx>
4 x4 m" J3 T' [& M7 M - #include <NXOpen/Session.hxx>5 j; a. J1 w1 y% q
- #include <NXOpen/ListingWindow.hxx>1 l5 @) B, h$ j# l& G3 R, f
- #include <NXOpen/LogFile.hxx>
. Q5 I+ M r/ F, E/ J" R! Z - #include <NXOpen/PDM_SessionSettings.hxx>; W V4 N% h7 _) `' Q3 k0 Q2 O
- #include <NXOpen/Part.hxx>( s, U$ L0 t/ V! |$ L) @
- #include <NXOpen/ParTCollection.hxx>1 q0 |, e. B9 [# Z
- #include <NXOpen/Session.hxx>
! N9 D5 g" O6 K2 m- w
4 A0 g8 _+ N+ C j4 q- using namespace NXOpen; // <== Very Important!% f2 ?) `% @5 l, M0 C/ X' n
- : A& {: g) _5 M: A* M. B" ]
- #include <stdarg.h>9 C! W$ j& a+ Z0 T; \
. \( S$ t/ }1 C7 F% u- static void ECHO(char *format, ...)8 W' ^1 J5 J; [/ m
- {
* J/ v$ Q4 v; ~8 A8 @ - char msg[UF_UI_MAX_STRING_LEN+1];' `( D. j7 S B7 _, c+ p
- va_list args;/ R1 \( `4 n& ?5 {& W$ s
- va_start(args, format);
/ P& K9 ~ H6 M& [1 u( {/ x5 E - vsprintf(msg, format, args);
! T+ V7 N; X9 U0 I - va_end(args);& r* N5 K* z( C4 s, ^ [( U3 y/ L
- UF_UI_open_listing_window();( \0 C m( z1 R& h9 d% Z5 Y; k
- UF_UI_write_listing_window(msg);
) z' ^" }1 q2 x/ ]2 Y - UF_print_syslog(msg, FALSE);
; b& ~$ O" r6 V7 ~8 }& ] - }4 R5 d( M3 E( N G
- ' O" U+ @4 H, d4 d1 v! v0 @
- #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
3 `7 E7 t# B3 V# s) T8 x6 Q - 2 t& R" \1 v) s5 o
- static int report_error( char *file, int line, char *call, int irc)8 x- X- V5 ]0 G0 e9 A4 b5 S$ l
- {; d# Y( P+ o9 v2 m. V' ` X# I+ k
- if (irc)/ @+ x: B/ R U& V
- {5 w$ J3 o/ [3 V
- char err[133];
3 V0 L9 b) {( e+ C3 Z
7 e! s" r$ F$ o6 w, i1 d- UF_get_fail_message(irc, err);5 m% V+ f" J/ G& Z
- ECHO("*** ERROR code %d at line %d in %s:\n",: z0 x/ x% p, p/ ]# }( Q
- irc, line, file); c; o' G* V% D2 z- h
- ECHO("+++ %s\n", err);4 x; L- Q8 D$ J, }$ N" W* ]6 M
- ECHO("%s;\n", call);
7 [& C* s" H- r - }
1 M) \' | o2 V5 i
: k5 p7 L7 R9 s0 M. `# g5 u- return(irc);
; H3 e0 A1 N9 \, K5 M# A - }* W% z& `; _) x. L% l
- " I s6 p" f; z3 L
- + o+ ]* @- K% R2 G- n
- static void do_it(void)/ I: u" l5 i8 M; J& W, _$ c$ e; z
- {
- `5 Q$ M' A, F1 ?3 q - Session *theSession = Session::GetSession();
* A' b5 S7 ~4 B( d - Part *workPart(theSession->Parts()->Work());# q; M" l' T M2 b) ?
- Part *displayPart(theSession->Parts()->Display());
. d* k- d/ _+ o -
5 _; i/ B& b5 D9 G1 ? - PDM::SessionSettings *sessionSettings1;3 \9 i, L% t# X
- sessionSettings1 = theSession->NewDatabaseSessionOptions();. ]* H# ]2 y' {3 [- L' c+ F
-
0 U+ k4 {0 E+ n9 ` - NXString CurrentGroup;
0 I8 P7 g. ~. I* o1 k, a0 H3 L) } - CurrentGroup = sessionSettings1->Group();
2 Q( r+ n$ f9 \$ u -
) q# u) E# s0 F# H2 f/ q - NXString CurrentRole;
+ o3 U+ K3 s' ?, E - CurrentRole = sessionSettings1->Role();1 `5 S$ X4 n8 n; l- E4 \+ p8 P
0 `" }" z2 O* [7 g- theSession->ListingWindow()->Open();- x5 n1 B' e9 @$ j- L! N
- 3 `# n0 ~. M' o7 K, o
- theSession->ListingWindow()->WriteLine("Current Group: ");7 q' ?0 d" ?- p, b0 J* M$ y! l
- theSession->ListingWindow()->WriteLine(CurrentGroup);
) ?, I& ^2 u% |# X/ f0 D, k" N - / T) t# Y& K2 y% ~
- theSession->ListingWindow()->WriteLine("Current Role: ");
; d3 v. G! B" j3 a6 C3 F! X - theSession->ListingWindow()->WriteLine(CurrentRole);
0 [0 j9 J& u# I$ h* W; w' `6 D - 9 W' k- g' c4 S, o5 h9 {; r
- }
2 m) n- {* f3 `/ H7 Z
' b- t. y1 {! a8 H6 }& w7 r# t- /*ARGSUSED*/
* [1 Q' |& {+ @* {) ~; i - void ufusr(char *param, int *retcode, int paramLen)
( p! W- [9 L. M+ g5 C - {
5 D& m9 y/ z9 o8 J7 ~: F, F2 [- Y - if (UF_CALL(UF_initialize())) return;
+ R# G W6 N/ }! n/ { - do_it();
4 o0 q& x L2 w" s: m: y - UF_terminate();. p7 J4 p$ J0 E+ q; c6 p1 P9 P
- }
& n6 ?( G6 \- x: F- A' O( k8 f0 y
" q, u$ |; w1 z; o: [% c' Q- int ufusr_ask_unload(void)7 F+ i2 W- T% s) H
- {- h4 ]( X, B8 X4 Z$ s- x" ]; \
- return (UF_UNLOAD_IMMEDIATELY);) B4 c1 f, V0 t* Y
- }' T) s0 M5 v+ t" m4 J* t9 I* P/ R- @: I
复制代码 |
|