PLM之家PLMHome-工业软件与AI结合践行者

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

  [复制链接]

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

admin 发表于 2018-7-12 11:12:47 |阅读模式

admin 楼主

2018-7-12 11:12:47

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

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

x
" F/ T# T+ t$ T/ x: N$ Y
NX二次开发源码分享】关闭NX后,做点儿事
3 m$ T) x5 T+ S) V/ O- t
( W8 T6 k: v- ]0 `# f, ^6 P! t[mw_shl_code=c,true]/*
" g5 G! P8 R/ K
" F+ I! b' O- p, R  u8 L    ufusr_ask_unload is invoked immediately following the completion of ufusr! d, }3 c3 J5 Q5 N" J
    (or ufsta when the dll is run from a startup folder) to find out when you
3 G4 O+ Y( u, e, C2 G8 d3 b: d    want the dll to be unloaded.  If ufusr_ask_unload returns! S2 r, _8 M7 w6 U# ~& G$ ?+ U
    UF_UNLOAD_UG_TERMINATE, the ufusr_cleanup is called right before the dll is  y0 t" _* m! U3 C
    unload when NX is terminating.  To prove to yourself that this works, set
9 \' \8 {" Q: N! r- O    the environment variable UGII_KEEP_SYSTEM_LOG=1 so that the syslog will not
8 V. f9 M/ N! b8 L5 l- M    automatically be cleaned up when NX terminates.  Start NX.  Use Help-> NX: K, h6 R4 D7 O, C
    Log File and make a note of the full path to the syslog which will be shown
- E7 ]& G0 k6 Q$ N/ u    as its own first line.  Run the dll built from this code (nothing noticable' o6 E( J% h* B  O3 o8 ~! G+ l5 m* G
    will happen.)  Exit NX.  Find the syslog and open it in any text editor to
3 j( K5 n' M3 P3 N$ _# x3 z" _    see this line near the bottom:- I1 I6 \; P# |5 u) e+ k& R2 D! Z
- E0 F+ K9 R8 j/ v2 V
NX is shutting down - running ufusr_cleanup
$ O, u5 ?' O" R# Z3 \& D1 j, Z9 @+ `1 g3 U/ b
*/8 ~% X) k# E3 L' ]  n
#include <stdio.h>+ a, A- M4 b" y. E5 s' p+ _7 Z
#include <string.h>" U, W0 n; Z: H4 o/ h  K4 I
#include <uf.h>) ?+ M% z) m; B* I  {& K# ]
#include <uf_ui.h>
# s. B. w% Q: P+ V8 b: s#include <uf_exit.h>* O# \" V7 M7 w: y5 U# K: `1 U

8 H9 F& A7 X2 N3 h2 T3 F* `1 l* W#include <stdarg.h># Y6 G8 W9 ]8 {" R
' ?8 o- e6 D. f( [- M# F
static void ECHO(char *format, ...)
% h5 M1 P) L0 V, D{
9 H* Q* b- p. j, j: r2 S    char msg[UF_UI_MAX_STRING_LEN+1];# t! u$ f3 n, X. r4 ^
    va_list args;
4 h! I9 S9 p! I; z; ]0 F1 r    va_start(args, format);& b! L2 U6 ?- W* y! ?9 q
    vsprintf(msg, format, args);
7 s2 p5 Y- C4 P# t! C8 X3 }1 M    va_end(args);
( m6 m/ _8 w7 [$ K    UF_UI_open_listing_window();
; T. Y- [: P( @* B# @; s$ a0 K    UF_UI_write_listing_window(msg);
* g8 [3 ]+ C/ W" F1 ]" }    UF_print_syslog(msg, FALSE);5 t9 h% ]+ {! h% J- `7 }
}0 d8 B/ W! y8 Y  H
1 r# J- f: y) T" r3 ]  a$ [( c5 c
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
$ B" z+ G1 Q+ A2 k  H/ N) g! x. x3 ]" N4 C
static int report_error( char *file, int line, char *call, int irc)0 M& S# u& s& M' p. ?  w; j
{0 v: ]3 G/ _, L: p' [4 t
    if (irc), I2 d/ t( E0 S: p& C
    {  h+ F, w  k1 _
        char err[133];
( G! J! W8 U8 [9 K
% g. l* \1 `0 `* Y        UF_get_fail_message(irc, err);: Z* K' I' b& C, ~6 Y3 i# R/ f
        ECHO("*** ERROR code %d at line %d in %s:\n",
* H$ r' B2 A3 K+ P. g3 R, {: A            irc, line, file);
6 @5 t) S0 r1 F6 b- L# J        ECHO("+++ %s\n", err);5 a/ t4 ^, B2 ?( `
        ECHO("%s;\n", call);1 G) r/ t2 b) R% B# G
    }
2 c. K; z* F+ A: `6 e/ W7 f) i% L8 V; o/ u0 V* P
    return(irc);
# D# F" W2 O4 U/ m) a2 M& h}
! V9 B  n, @7 Z, G0 w4 {  K6 c5 l4 O2 `8 |( h$ M: r, q
/*ARGSUSED*/
9 k7 h3 Q5 d( y1 a, Y6 z% f& K/ pvoid ufusr(char *param, int *reTCode, int paramLen): L: s1 c. v- J0 ]1 r. b
{" d2 K; }3 \1 q! d2 Z0 y6 b
}
3 }9 U  n7 F# \/ h& A7 @+ |
! i8 {- T0 t$ t* @& M0 B/*ARGSUSED*/
" M9 H5 d) w% i+ x  d2 qvoid ufsta(char *param, int *retcode, int paramLen)  K& q/ `, v4 N7 n; r
{) j" `) S! a- V2 Q; H- ^9 w# v
}. c; y7 h$ u# \1 x9 x" Y, M

" \! d% S0 |, w" b1 P/ Gint ufusr_ask_unload(void)
* w8 C9 `8 W0 a& X{  N3 u- N& z1 S3 l
    return (UF_UNLOAD_UG_TERMINATE);: _  h" e2 L, ^) Y& Q  E8 a
}9 i; q2 {" B& N/ F. I/ H

0 \/ U4 I5 B, }# U( K2 Qvoid ufusr_cleanup(void)
5 W8 S. |) D0 y* Q: O. [' p{& F3 S/ N) |0 c. H/ Z
    ECHO("NX is shutting down - running ufusr_cleanup\n");5 V9 Y3 K( h9 h' ^) B( Z

* r% B5 J8 ~; a# |$ s$ W    /* put your code here */
" r/ p2 C3 f* X2 y}[/mw_shl_code]
& S! |8 W9 h5 h5 F7 z; }
上海点团信息科技有限公司,承接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" C. \  w# l7 E( l# M: ?
请问这个函数是怎么用的?有什么用?
4 |6 ?' q" ^0 B$ G1 C: `
入口函数 改成 ufusr_cleanup
* u: t/ Z- l* r* q) |# V& f& N( I7 O* A& a. W, ]
意思是 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二次开发专题模块培训报名开始啦

    我知道了