查看: 4687|回复: 5

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

 火 [复制链接]

2480

主题

1280

回帖

8万

积分

管理员

PLM之家站长

积分
82278
QQ
发表于 2018-7-12 11:12:47 | 显示全部楼层 |阅读模式

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

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

×
& r: P* W9 ?7 T/ {3 `
【NX二次开发源码分享】关闭NX后,做点儿事
. m3 R9 H4 H4 N: F, d- p; H# H. i; @' v4 W  N  m* p8 |
[mw_shl_code=c,true]/*
# W7 f+ x, d: S9 H/ W2 N
6 L, x, [' @! \* h    ufusr_ask_unload is invoked immediately following the completion of ufusr7 E+ H; C3 b/ q
    (or ufsta when the dll is run from a startup folder) to find out when you
# ~; s+ s5 Y6 i6 h* F    want the dll to be unloaded.  If ufusr_ask_unload returns
  x$ u  ^% I9 c2 K! l/ ^# F    UF_UNLOAD_UG_TERMINATE, the ufusr_cleanup is called right before the dll is: X% D& Q" f0 X! G5 p1 r
    unload when NX is terminating.  To prove to yourself that this works, set
+ Z; N+ y8 g% D2 Y    the environment variable UGII_KEEP_SYSTEM_LOG=1 so that the syslog will not
8 m2 }) y, g" Y* h" K    automatically be cleaned up when NX terminates.  Start NX.  Use Help-> NX& V! m; y9 I  D0 Y: D. K
    Log File and make a note of the full path to the syslog which will be shown! x' ?, u6 v: B7 D, V8 v1 f
    as its own first line.  Run the dll built from this code (nothing noticable
/ P9 M) ~5 C/ w: c4 T' ?5 e    will happen.)  Exit NX.  Find the syslog and open it in any text editor to( v% [- H/ p2 \
    see this line near the bottom:
, g% H% }7 ], j/ A: R
/ h& r# l" F& ^$ f. W0 V" o/ jNX is shutting down - running ufusr_cleanup* E, f9 e0 y1 h4 U( Y, r( ~
- o( I6 }- u. k% y
*/" m4 F" v# f. [3 P
#include <stdio.h>
2 T9 P" Q: u* W% f#include <string.h>
. _. R) i% U. g#include <uf.h>
' l$ U: [3 U) R: ]- v3 ?; l- K#include <uf_ui.h>- y0 c4 X) d! ~
#include <uf_exit.h>
: n/ ^0 R- p! D7 F3 U6 H# ]
1 s! |6 P& x  Q8 N4 A9 }- S7 m#include <stdarg.h>% |5 [1 Q; b4 Y8 F
& o- Z' {$ O$ N1 {
static void ECHO(char *format, ...)
9 v, a, `2 x$ e0 p8 n{
3 M$ L6 _! V" c2 J    char msg[UF_UI_MAX_STRING_LEN+1];5 g3 s7 K+ u* K7 ^: Y
    va_list args;
+ s8 g) y1 a. j7 U9 l    va_start(args, format);9 _9 K) u; V8 S( _
    vsprintf(msg, format, args);% n" X, [2 v5 W0 f6 f
    va_end(args);
0 B, Z9 p) C) i% S6 h% v7 b    UF_UI_open_listing_window();" o% R3 j* ~$ \, I
    UF_UI_write_listing_window(msg);
8 Q% n9 j4 x- s    UF_print_syslog(msg, FALSE);
, h4 Z& }7 B- Q- X# o}
; G. C1 M6 i7 H* F- y6 x* k; m" W1 n2 Y/ C
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))# f8 Q" {: `* q3 ?& F
6 n; t* w; G7 t+ W1 O
static int report_error( char *file, int line, char *call, int irc)$ Y& A3 f$ @8 K0 S& q7 H
{1 ^# K$ X# ~  ~  K6 d, x, A% I
    if (irc)
1 J: L9 x* {7 b    {
. e" K6 L8 p4 _# N) n3 V+ d) ^        char err[133];
4 Y% D' z9 L8 e8 f
) H: J( t+ H6 @( Z* x        UF_get_fail_message(irc, err);
+ a1 X- i4 g% d3 o7 s5 w- j% h        ECHO("*** ERROR code %d at line %d in %s:\n",$ {( e; n0 Y5 e) f2 o
            irc, line, file);
) ]  ]4 w# A/ {3 U. c( H. `        ECHO("+++ %s\n", err);
! _* f! E7 P$ I3 X. M* x% U( k# Q( d        ECHO("%s;\n", call);
) P. Q" u* D. B2 B0 L    }
" A$ {2 Q2 s( R: _3 h; m4 @. }! h$ u: B2 w& e9 b, e- v
    return(irc);* Y7 {. }, F% O- l8 A
}& s/ x6 l) s& Z5 }% U
. m2 O5 _. E% T5 U2 T5 K
/*ARGSUSED*/* C. w1 m6 ^$ L; ^$ j3 Z/ V6 O
void ufusr(char *param, int *reTCode, int paramLen)+ L1 |( a& I$ {
{$ L  p0 P$ p5 n( D
}
, k9 g$ S9 T8 d. m0 Q7 X9 @' E. j; u  ~3 s( I0 o
/*ARGSUSED*/0 {) a$ A! C0 n0 G
void ufsta(char *param, int *retcode, int paramLen)2 |8 K" D, t/ [* b
{, G+ K/ H% v" W3 L* ^# L5 w
}
9 `& F. o- o( X* c/ \( i$ f( ^% L* Z/ H! z
int ufusr_ask_unload(void)
3 i' F8 O: A- a4 }{2 \- ]5 [# O- M6 w" k6 y1 ^# P
    return (UF_UNLOAD_UG_TERMINATE);9 ?' P9 h1 I# t& s* Y5 i5 q+ \
}
5 q2 h. ^+ u- v& R
9 W% O5 n! N" z' C, qvoid ufusr_cleanup(void)
" a6 R2 H( }- V. B9 |/ ~- G' M{$ I0 M* E) I% ?3 i2 k; l
    ECHO("NX is shutting down - running ufusr_cleanup\n");6 _+ K: ]' f. s: d9 R

6 X( {4 J- D) L  a: \    /* put your code here */
4 U  S9 |1 Z! s1 @" Y) n}[/mw_shl_code]
$ C! W$ M8 \1 F1 ?) x' f  M0 Y0 e
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

1

主题

45

回帖

203

积分

培训VIP会员

积分
203
发表于 2019-12-25 08:49:24 | 显示全部楼层
请问这个函数是怎么用的?有什么用?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

2480

主题

1280

回帖

8万

积分

管理员

PLM之家站长

积分
82278
QQ
 楼主| 发表于 2020-2-13 08:43:55 | 显示全部楼层
licxsw 发表于 2019-12-25 08:49
  q7 T  n8 I+ B/ o' j$ G9 E请问这个函数是怎么用的?有什么用?
/ ~2 {7 u( i7 r! Y5 h$ `
入口函数 改成 ufusr_cleanup
% X( @, O5 }- f0 @: Q* r8 U3 m: w% W" C2 n8 _5 T3 l( W
意思是 NX 程序退出后,你可以做些事情 ,具体做啥可以自己写,就是个入口
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复 支持 反对

使用道具 举报

1

主题

45

回帖

203

积分

培训VIP会员

积分
203
发表于 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.doteam.tech
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部