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

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

  [复制链接]

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

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

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

x
% T9 R* m) s* a: I% I% d6 j
NX二次开发源码分享】关闭NX后,做点儿事. J7 F! o  E7 m

( f+ v6 |4 w; f$ J/ X& E[mw_shl_code=c,true]/*
' s, f$ L' `7 F8 t" x. w% u+ b
# V9 d' W. X$ A5 M5 o( ^    ufusr_ask_unload is invoked immediately following the completion of ufusr
0 @& c- F5 T4 j0 D    (or ufsta when the dll is run from a startup folder) to find out when you
  P+ L  T: D' n4 S    want the dll to be unloaded.  If ufusr_ask_unload returns, R& V5 o) h0 T1 r, P" k. u$ R( T
    UF_UNLOAD_UG_TERMINATE, the ufusr_cleanup is called right before the dll is, H, G5 N# a. I# G+ ^
    unload when NX is terminating.  To prove to yourself that this works, set3 @$ P: o! b/ L
    the environment variable UGII_KEEP_SYSTEM_LOG=1 so that the syslog will not
' U: ?7 ^% J3 ?3 m- R" z* D    automatically be cleaned up when NX terminates.  Start NX.  Use Help-> NX
1 ?0 y$ t6 }8 }1 }* C    Log File and make a note of the full path to the syslog which will be shown& G  \5 }0 I3 t+ t* b
    as its own first line.  Run the dll built from this code (nothing noticable+ {" A6 C- u, e# A8 A6 f, R) C
    will happen.)  Exit NX.  Find the syslog and open it in any text editor to
% [, ?8 g: h+ l    see this line near the bottom:6 G! m" G, Y, A) g5 l0 a
  K9 P) C  _# }/ v  J
NX is shutting down - running ufusr_cleanup
. R! M  u+ v. E. u! }  n/ W, W5 }5 s  S; f2 ]2 K
*/  |5 O) y) u8 p) w
#include <stdio.h>9 U. m3 F  \8 @8 Y' o
#include <string.h>' Y9 x# f* J: p8 l1 y3 K8 Q6 A3 c
#include <uf.h>9 K' H6 R) a- x: k; Z
#include <uf_ui.h>
( u) @# l( S- K: T#include <uf_exit.h>
" N/ Y2 a: i% P8 P8 x0 i" Q2 Q3 I% \, A
#include <stdarg.h>
- C/ t% Y9 z# h/ K2 n0 H( k1 `! @% s1 D
static void ECHO(char *format, ...)
( l. s% P' a; M: ?  f! n0 D$ k{
6 P, M8 {1 f' n  D- j    char msg[UF_UI_MAX_STRING_LEN+1];8 V, U/ v$ U$ C! e  y2 Y4 p! v
    va_list args;! c) r" }) p% o8 J2 c  b" A/ X6 k) O
    va_start(args, format);) b  O. x7 m6 [0 I# `! {2 s
    vsprintf(msg, format, args);
8 b. v/ n3 Y' h. Q    va_end(args);* ?/ }. z( X- [8 M9 b
    UF_UI_open_listing_window();7 P2 s8 s( g9 s( [" i3 B$ g
    UF_UI_write_listing_window(msg);5 A2 W2 p% e. e8 ~' t
    UF_print_syslog(msg, FALSE);; K# ^  B' [8 B/ c
}* @  Y/ r# c* R: N4 A
9 S3 r; g/ a3 y* w6 Y4 U6 F  r
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))& u. w3 v% h5 k

' W6 w( r4 C. M& ostatic int report_error( char *file, int line, char *call, int irc)4 c9 x$ S5 d& {, B/ T( P
{
% u, p* X+ |) o9 |$ a; }    if (irc)  [: ?( k7 R& ?
    {
  F" r2 Y. i% X# R        char err[133];
, c) j+ ?+ T5 Y  H
' e! p2 m* _- M7 a, _2 `9 S        UF_get_fail_message(irc, err);, g0 ^5 i. l# v# p: s
        ECHO("*** ERROR code %d at line %d in %s:\n",
" M4 |1 f+ c, a$ q            irc, line, file);
+ H+ u; S7 X) Q7 x        ECHO("+++ %s\n", err);& R7 u  [$ D) i* i; i
        ECHO("%s;\n", call);
  }% U+ f8 M7 m1 n* b  u9 Q4 |    }
$ ]' k+ |% |; b$ S$ p6 Q0 U/ y
8 m! g1 {+ e* F/ c5 s    return(irc);& l! U/ g% g# O! I4 i7 J* q+ F
}
0 X- V* L7 o. Y0 w: w- W
. b9 A' g# ^8 T/*ARGSUSED*/
  H8 F, y2 X3 X) C1 m3 vvoid ufusr(char *param, int *reTCode, int paramLen)
+ n6 r, P' g( m& y' Q{
5 s$ Z$ d8 Y& ]) M' r1 u( M5 J+ A}! j$ r5 r( V; c' P, V9 y" c
' M0 C% k/ j# O" M* Z; t+ v5 g
/*ARGSUSED*/! P) `( B- e4 Z; m- d2 X' x1 `! z
void ufsta(char *param, int *retcode, int paramLen)& q0 Y" ^0 h9 Z# i
{( v3 V3 z$ z9 \# b* v. y9 B
}
2 r& B8 ~# p. a; Z7 |
" M6 n% \4 z$ [3 Dint ufusr_ask_unload(void)8 V$ o/ t. C* ]: S! [# ]1 c( q/ J
{/ w/ T5 y* A$ {+ Y1 W) N- |
    return (UF_UNLOAD_UG_TERMINATE);! _. }) V& H' v1 K' I/ P" @
}
6 p* i' P5 M  G( g; |2 Y9 s* o
/ O8 S& U4 w$ ]4 _% g  ivoid ufusr_cleanup(void)$ F" a& w) H" y: W/ y3 T
{
6 b9 t. r5 W8 |8 `9 r! h    ECHO("NX is shutting down - running ufusr_cleanup\n");+ Z3 U- X; L0 N: F5 f
) ~7 c7 p. }& J* E5 D
    /* put your code here */' A" F4 a$ x$ P$ o/ I. Z; a* t
}[/mw_shl_code], q5 O- o* U2 y/ X
上海点团信息科技有限公司,承接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:491 @' |, a, i; K6 A/ p# Z+ G0 i
请问这个函数是怎么用的?有什么用?

# V( k% J1 ]6 n  ?. T. m/ o: @% |; c入口函数 改成 ufusr_cleanup
  A+ ^( U) F; ?  T
, U4 M; t$ z2 |, a意思是 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二次开发专题模块培训报名开始啦

    我知道了