PLM之家PLMHome-工业软件践行者

[二次开发源码] 【NX二次开发源码分享】关闭NX后,做点儿事

  [复制链接]

2023-1-10 20:46:56 3993 3

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

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

x
1 N2 b9 K# f' p9 s! n' d
NX二次开发源码分享】关闭NX后,做点儿事/ m: ]: U4 Z: A- ^1 R/ i0 h
. j3 I' j' c6 i' r( a- m9 {% q
[mw_shl_code=c,true]/*  n+ {5 j6 U, Z
1 S, q& v) |; r& j4 ?$ }/ i
    ufusr_ask_unload is invoked immediately following the completion of ufusr9 L& m4 B. J# c8 n
    (or ufsta when the dll is run from a startup folder) to find out when you
3 L: j3 \9 k3 m/ [& d* m4 N    want the dll to be unloaded.  If ufusr_ask_unload returns
4 g0 c0 D0 Y% ]3 o: S    UF_UNLOAD_UG_TERMINATE, the ufusr_cleanup is called right before the dll is! n/ R: \  H1 G9 ^8 z5 W
    unload when NX is terminating.  To prove to yourself that this works, set
2 X. }9 W# K9 X    the environment variable UGII_KEEP_SYSTEM_LOG=1 so that the syslog will not  ?# l" O$ f* I& [) H
    automatically be cleaned up when NX terminates.  Start NX.  Use Help-> NX5 G* Z& ]5 s* M# M
    Log File and make a note of the full path to the syslog which will be shown
/ W& _# W! }  P, \, T9 K* m    as its own first line.  Run the dll built from this code (nothing noticable
8 Q0 }, g# ]+ l5 t    will happen.)  Exit NX.  Find the syslog and open it in any text editor to, Y8 ^* e$ {1 r  n% A+ P
    see this line near the bottom:
2 M1 G6 K) C" M
  M: e2 d  D7 G, X8 f/ b: S) rNX is shutting down - running ufusr_cleanup  D. }" O9 D- v* M9 O% M

) [% I, v6 a2 O+ C& B! l*/5 [8 E: ]3 Y, f) z8 S; c
#include <stdio.h>+ g2 y% Z7 c5 q' E; [1 H! D
#include <string.h>1 N' P: w$ x" ~3 z' \# C  ~: [" z
#include <uf.h>
; c& ~; A/ ]& ?/ e/ u) v/ y#include <uf_ui.h>
- `( A5 o% v- _% L  m#include <uf_exit.h>
/ P3 E# j: `8 e
8 J2 C: d* d- K. u# x1 h1 I* m#include <stdarg.h>
3 I8 h" O- i9 p# y* @+ ?
# i! J. A0 ]: g8 Istatic void ECHO(char *format, ...)' ^- k* q* A5 i3 ]& G% U% r
{
7 F! q/ s8 R. r: m% I' k: K    char msg[UF_UI_MAX_STRING_LEN+1];- X. x& D. T. x! l4 {1 ?1 U, H
    va_list args;! u9 q" m: U0 I, s. s7 z3 w
    va_start(args, format);
& ?* r6 j- Y; V* W4 Z5 X) k    vsprintf(msg, format, args);
0 R/ Q6 S; m* @6 W3 p6 {: @    va_end(args);7 y* F6 w4 c3 G
    UF_UI_open_listing_window();. f4 O1 B  Y1 u( g- E6 `0 e5 w, D
    UF_UI_write_listing_window(msg);
* w1 |; F9 C$ @0 j    UF_print_syslog(msg, FALSE);+ |2 ?& [) l! Q; h9 m8 V$ d
}" ?( H* ^* [/ I% t) P+ R3 x
% u8 I8 B" V$ F' ~( \, b2 O8 f  J
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X))). u% S( }$ P$ {1 U, F

9 `+ F; J, h( I) Pstatic int report_error( char *file, int line, char *call, int irc); [. l( H9 u/ R# f8 H. t
{) b3 u1 v; ~+ o- d8 o
    if (irc)
, u( n) q7 `9 @! _( P* q+ Z6 X$ k    {% [% \7 ~: K1 e% a
        char err[133];
9 B3 u% Z5 R/ f0 j! c8 }) o3 k0 E0 T: c2 ?
        UF_get_fail_message(irc, err);
. g' m5 B' x8 t( m% {& N        ECHO("*** ERROR code %d at line %d in %s:\n",
4 K. c/ P0 F0 z! Z            irc, line, file);
5 B3 o' ?7 [, O        ECHO("+++ %s\n", err);0 w+ }/ D! f$ w8 D6 [
        ECHO("%s;\n", call);
* J* q2 k& T0 m3 f3 q' E    }4 U; _5 W) I" q8 s0 C
/ I0 R, u& @9 E" a0 v" D1 @
    return(irc);
  \9 N3 s5 q( j- x! J( T}4 _) ^/ o8 q) ?7 n0 e
; x+ _; Y% ]' D2 Q  Q! P3 X
/*ARGSUSED*/
3 c0 r2 Q& ?  @# ]7 q6 Evoid ufusr(char *param, int *reTCode, int paramLen)& C8 N" n. O3 K1 x& J: j
{
% g) {6 g1 P* x  d}! K1 h' T( _. E7 w9 C: v
) k# {; X) h9 s5 K
/*ARGSUSED*/( J8 P3 a' H, k
void ufsta(char *param, int *retcode, int paramLen)
& d* T% E1 B* B; ?4 l5 E{
" d6 f/ }: j  I# ]- V: j}
7 Q, x9 H4 x! O1 K% W; [. F. K* ^7 ^1 ~5 ~% M' L, L
int ufusr_ask_unload(void); r5 u9 D# c+ `7 @7 l, d
{
6 P8 N+ s9 T8 `    return (UF_UNLOAD_UG_TERMINATE);: C$ y1 u) I! t' e
}7 z* I4 S( t9 o: x
. _; \# L4 n/ L/ `  a: e& u
void ufusr_cleanup(void)& K/ n7 }" b# J5 M, Q6 w2 k
{
% U# D, U/ i, k+ R7 H    ECHO("NX is shutting down - running ufusr_cleanup\n");
$ Q' G! d: R1 ~) A8 ]4 J
6 w2 M7 n& O" t2 N- D1 _8 f: T; x+ |& g    /* put your code here */
3 r7 s& C  Z6 s7 ?" S% @$ ?8 `0 m( S}[/mw_shl_code]
8 K9 z$ b- k/ \- X& g; V
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

全部回复5

licxsw 发表于 2019-12-25 08:49:24

licxsw 沙发

2019-12-25 08:49:24

请问这个函数是怎么用的?有什么用?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.diantuankj.com/ doTeam.tech
回复 支持 反对

使用道具 举报

admin 发表于 2020-2-13 08:43:55

admin 板凳

2020-2-13 08:43:55

licxsw 发表于 2019-12-25 08:49
- ]6 B3 e- o/ P4 g9 b0 B; b3 v请问这个函数是怎么用的?有什么用?

) B0 U/ z) \& L" _入口函数 改成 ufusr_cleanup
, P& J* x5 u! ^8 _, @& F
- x+ W) M4 j; k& A6 Y意思是 NX 程序退出后,你可以做些事情 ,具体做啥可以自己写,就是个入口
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复 支持 反对

使用道具 举报

licxsw 发表于 2023-1-10 20:46:56

licxsw 地板

2023-1-10 20:46:56

测试了 ufusr_cleanup入口处复制文件到指定目录下,不成功
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了