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

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

  [复制链接]

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

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

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

x
# ]  `$ Q/ Y( _2 d9 i
NX二次开发源码分享】关闭NX后,做点儿事$ L- G0 O5 g0 r2 J/ @$ w" f
1 f7 ~! o- }; C6 o
[mw_shl_code=c,true]/*
' n% Z9 E7 F% G7 g) e
& B! U+ N. s" q- F. _    ufusr_ask_unload is invoked immediately following the completion of ufusr
) [: d7 S5 t9 M3 w/ F% }    (or ufsta when the dll is run from a startup folder) to find out when you2 w. @/ N, L; J1 @! u
    want the dll to be unloaded.  If ufusr_ask_unload returns
% @9 v, T' O8 G) K! X' ^( g    UF_UNLOAD_UG_TERMINATE, the ufusr_cleanup is called right before the dll is8 E  Q7 M& K0 {# v* W
    unload when NX is terminating.  To prove to yourself that this works, set& S4 \+ o8 _9 ^# R% i, G
    the environment variable UGII_KEEP_SYSTEM_LOG=1 so that the syslog will not
) v8 q5 T( m1 V3 }) v, Z9 J% A) u    automatically be cleaned up when NX terminates.  Start NX.  Use Help-> NX7 W) {4 G, A! ~# y
    Log File and make a note of the full path to the syslog which will be shown- l9 g$ V; t8 x) S7 a
    as its own first line.  Run the dll built from this code (nothing noticable5 n1 \& M0 i1 s* z: ~
    will happen.)  Exit NX.  Find the syslog and open it in any text editor to
' K. K8 X$ }, K/ _, O    see this line near the bottom:1 r" y$ Y: e5 Q6 d- V9 o1 M9 Z
; i; L& J  }& K
NX is shutting down - running ufusr_cleanup
: f" h. H5 \) d* _
* M! [7 Q+ |& M/ O*/
8 i* N% B' d; Q8 X9 }5 _' E#include <stdio.h>
: a6 \+ D' {% H* z#include <string.h>: `4 E4 \, F5 }4 @1 c
#include <uf.h>5 {2 ?" C0 O4 }/ [
#include <uf_ui.h>* q. J+ [& K. ~* R
#include <uf_exit.h>9 K5 m  M# ~; W# X3 u

+ Z6 @' @. b3 G8 M/ g#include <stdarg.h>( p: w3 p) D3 g8 ~

7 w8 `8 a9 u& Y+ Jstatic void ECHO(char *format, ...)
! U* n4 X6 W9 t, |0 s" R{$ c9 ?" I, r: v
    char msg[UF_UI_MAX_STRING_LEN+1];
  j' w& N, i4 `! L  v. s" }; F( ^    va_list args;
8 i) _% n8 q" O( c3 @9 M( P4 @    va_start(args, format);
) o8 N5 Y' ^6 q/ v    vsprintf(msg, format, args);
, k* Z5 a. B+ i( |5 c    va_end(args);' n+ V8 n$ ~; x# d2 c" Y" g& ^
    UF_UI_open_listing_window();! |& J/ I9 o* K8 P
    UF_UI_write_listing_window(msg);/ I1 \. g! g' u
    UF_print_syslog(msg, FALSE);( \% l. i, j- _
}
0 p  a- y( p5 i+ f. ~9 g
; t" s" S7 w0 f' ~: N8 P  Q6 y#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))! W- y! S% R& U, i! _; l- I1 H
1 j! @% U: ^' C5 f; x7 r/ h' d
static int report_error( char *file, int line, char *call, int irc)
* `" v* E2 V: g6 I" i3 p. U2 {{1 H+ ?. M( F% b. `2 s
    if (irc)
( b' B- w* u$ Y  @6 {5 b% X2 b    {
0 S, d* @; K5 r        char err[133];, E8 O, E* p$ o& d
  q$ L5 C, ^$ V& m
        UF_get_fail_message(irc, err);1 }6 S" |9 |/ H9 l
        ECHO("*** ERROR code %d at line %d in %s:\n",: R6 @2 C: }0 n! ~5 r) t
            irc, line, file);$ X1 T- q  D+ V! u( K2 ?
        ECHO("+++ %s\n", err);
7 l- N4 q+ F: y5 T7 f' i        ECHO("%s;\n", call);
7 m0 W. J, P  G8 x7 }0 e    }- D) O; C- O' M( W( m' i9 z
% o* X% \0 E* U5 L) u3 `
    return(irc);
8 e1 [& t  R: F) f: o}" q: c6 K1 g! s8 g0 ^' W6 Z; e
: z6 r; Q# B. G  B  H  t3 G
/*ARGSUSED*/5 f; ]! q) a- x/ |! u, w7 _
void ufusr(char *param, int *reTCode, int paramLen)2 A1 k# Z  e+ a& g, Z
{
. |: a* ^" z. H* s2 j* [0 y}8 C! M8 p/ |# P8 ]8 g! {: ^" w

3 T1 j$ ^; \5 Y9 j+ |! a9 ^. N" T( x/*ARGSUSED*/
8 p8 Q) \: [$ b: |) rvoid ufsta(char *param, int *retcode, int paramLen); ^4 S) p6 f! {8 p
{2 e2 x6 d" x. Y( {5 x: d& Z
}
0 E9 A4 M& x1 O+ f" |4 N
8 o5 q0 N4 u/ D! kint ufusr_ask_unload(void)4 U2 @- d1 y4 O
{& h" x% _9 t/ w# Q* M) K. c
    return (UF_UNLOAD_UG_TERMINATE);
2 C; d0 R- O% f}. m! Y0 P9 q& k5 U& P0 R

0 v5 `& i; N0 `( jvoid ufusr_cleanup(void)
8 I) P4 D, W6 h" R" R, b0 A{
9 _; v+ B2 K- B/ {7 `# r  W' D    ECHO("NX is shutting down - running ufusr_cleanup\n");4 c/ `6 n0 O( t6 i4 H/ Z2 f- y# g
+ }' m8 O% J. i- q& T# X
    /* put your code here */; z: ^( r2 x2 O5 ^) u
}[/mw_shl_code]
$ w1 I, H! V  y  u
上海点团信息科技有限公司,承接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
$ _% J% c5 W8 V3 ~+ c+ M请问这个函数是怎么用的?有什么用?

" c- d$ j# i' q7 L  s3 R/ F6 @/ U入口函数 改成 ufusr_cleanup 9 R" u5 h* I6 t/ |$ C
! W' F3 Z+ G2 B. c8 t! j8 V. z
意思是 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二次开发专题模块培训报名开始啦

    我知道了