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

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

  [复制链接]

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

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

admin 楼主

2018-7-12 11:12:47

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

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

x

( ^( G+ _, a  _1 }- G7 X' GNX二次开发源码分享】关闭NX后,做点儿事
' X: [3 a& F3 l; ^0 m
* P7 {( [6 C# Y4 Y[mw_shl_code=c,true]/*
1 [7 \, [1 ^- S$ ^$ O) I
1 t2 e: K. U; e' V5 F7 U8 @" a    ufusr_ask_unload is invoked immediately following the completion of ufusr
! I3 H0 i* H7 I/ B" ^, f6 C" g" E6 s    (or ufsta when the dll is run from a startup folder) to find out when you0 x4 \; ~+ k% Y8 p. A( B) l3 @
    want the dll to be unloaded.  If ufusr_ask_unload returns
6 F- O) K1 k. P6 c# V0 R+ ]    UF_UNLOAD_UG_TERMINATE, the ufusr_cleanup is called right before the dll is% F0 X% j7 X' d/ L1 k
    unload when NX is terminating.  To prove to yourself that this works, set
. l/ p4 [) h2 c! _& K    the environment variable UGII_KEEP_SYSTEM_LOG=1 so that the syslog will not" y0 \" h  j. F. ]0 j
    automatically be cleaned up when NX terminates.  Start NX.  Use Help-> NX0 q8 r& j# [: H8 h* w7 V  _  R
    Log File and make a note of the full path to the syslog which will be shown
6 l% {& U  g% ?    as its own first line.  Run the dll built from this code (nothing noticable
1 u/ Z, p# p3 V2 `+ l    will happen.)  Exit NX.  Find the syslog and open it in any text editor to& c8 b7 f# K. R& q  g' ]
    see this line near the bottom:5 F" l1 w+ I* j) w/ t
0 E( L( ?; @4 a4 j6 S- z1 l6 ]8 J
NX is shutting down - running ufusr_cleanup- \# K+ c  c3 g5 X9 u) E
% i$ e4 P( x# j  g
*/% ]0 ^. X9 A2 Q
#include <stdio.h>- W8 z5 n' d9 A
#include <string.h>) c' c0 Q( @& z  r
#include <uf.h>8 W3 L5 b6 h, U
#include <uf_ui.h>; \8 E( \' V3 }: X8 j
#include <uf_exit.h>& a1 r+ W/ v# z$ i
* S: G- e# m$ X" f
#include <stdarg.h>
( _  C: H7 R* m( ~6 B- ^. O
1 \& e. d/ D- k9 s8 U; mstatic void ECHO(char *format, ...)& Q/ i) v7 g- d8 V+ y% ?; Q  j
{2 Y' R- A" r; a7 x! t
    char msg[UF_UI_MAX_STRING_LEN+1];
, j$ |% i# \  Z7 e/ ]. t    va_list args;0 a  U0 i1 a. B
    va_start(args, format);: @" |. O8 G; b* p8 `% K% Z8 }
    vsprintf(msg, format, args);
0 t$ f+ `" s' x6 h' A; J    va_end(args);! X$ v+ \! Y' Z( o+ j
    UF_UI_open_listing_window();% S8 T2 o; R2 g( j
    UF_UI_write_listing_window(msg);" i, T4 W: ?- B3 Q( D
    UF_print_syslog(msg, FALSE);
! k% D/ |6 s# j9 l1 G}5 `, I" i  C2 ^" J, S

1 _7 l2 @/ Z2 @. {7 j& _4 P4 s#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X))): T8 L9 V  ~" a, ]$ M1 M9 T5 V

/ b9 T5 h; E' tstatic int report_error( char *file, int line, char *call, int irc). p' F. J& l* O% p' F+ I  |% S
{
8 M" P# {0 z( A/ m8 \" X1 K    if (irc)
' r% [) b1 s3 _( i    {$ i; _9 ^( l" }$ _7 W+ `$ j
        char err[133];( X6 @& G, `5 T5 B) o% [
& {0 `: J3 t9 q' t2 i0 W5 h
        UF_get_fail_message(irc, err);* U7 F* `5 i, F3 e: N
        ECHO("*** ERROR code %d at line %d in %s:\n",, ]! C6 T0 V- N, w2 t# ~
            irc, line, file);% y2 t+ w: ?$ g$ J8 r! M% ~3 p) t
        ECHO("+++ %s\n", err);
) g0 E: ^% f1 ?3 R        ECHO("%s;\n", call);6 `0 m0 Z  }6 N  @( h8 z
    }
% W- W  d3 v* ?6 a2 L0 [5 K* o' T, ~' }6 k! K* G
    return(irc);- D' V, f) k7 W2 C
}- B1 z9 Y3 N& ~  p) c( [( ^) ^
3 L/ w4 i) A9 Y! n: p. r
/*ARGSUSED*/
/ }9 o6 E2 n  E- }- {5 ^void ufusr(char *param, int *reTCode, int paramLen)
4 E! K% ~( \/ ]$ V& o9 l{
  F3 @- B$ I& h- `* ^/ `% Q- L$ Y1 w}& S: O! i; N! G+ i) z

; O. z! _2 |9 |3 R/*ARGSUSED*/
6 A5 I6 e( X/ O% nvoid ufsta(char *param, int *retcode, int paramLen)
& z% T7 ?( S% @" ~4 M. A# Q) P{
4 |0 \6 i; v& D$ q}& g3 @% R3 K! a3 ?: y. e4 _
- c. D$ k( ^5 b2 c2 `. Z
int ufusr_ask_unload(void)0 v" B% X$ S. C1 x3 ]0 w
{
5 e! I& g3 j5 T3 W0 ~    return (UF_UNLOAD_UG_TERMINATE);
! a! S7 ^9 V% K* F/ K4 E+ A8 P}; A1 c! `! X8 g
/ {. r0 E7 j8 i6 _2 V. E' g" h
void ufusr_cleanup(void)
  h5 e. O- w( m; I! N) C{- W! m3 V% f8 B! {
    ECHO("NX is shutting down - running ufusr_cleanup\n");( f& b0 s5 _& I0 |3 E, ]

, t- X% h+ d: Y6 ]  f% _3 @    /* put your code here */8 j6 \4 z$ U  L5 Y; U$ h
}[/mw_shl_code]% G, N8 L- \9 Y' h$ I
上海点团信息科技有限公司,承接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! {1 E' ?+ d# H# F" B! L. l
请问这个函数是怎么用的?有什么用?

6 n' S: s' \' @2 \+ H0 X入口函数 改成 ufusr_cleanup 0 k/ a( N% I" v* y! q6 O* I. }0 @
4 c$ H% p9 z/ h% }2 Z" ~2 ~4 i6 ~( 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二次开发专题模块培训报名开始啦

    我知道了