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

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

  [复制链接]

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

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

admin 楼主

2018-7-12 11:12:47

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

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

x
( u5 t5 r  t2 u
NX二次开发源码分享】关闭NX后,做点儿事
+ l/ ?( J, v7 h& Q- f6 K5 A+ Y: V3 c' N
[mw_shl_code=c,true]/*4 j, u3 J7 H2 n) [& Y
- j# D) A7 k8 A! g( U' P  V/ v
    ufusr_ask_unload is invoked immediately following the completion of ufusr. O. R( w7 v# L1 G
    (or ufsta when the dll is run from a startup folder) to find out when you5 Q: _" p- p" P  Z5 {% H* n
    want the dll to be unloaded.  If ufusr_ask_unload returns4 U1 k) e' y) a8 u5 e# K/ x0 b
    UF_UNLOAD_UG_TERMINATE, the ufusr_cleanup is called right before the dll is0 \1 S1 n! u* L3 p
    unload when NX is terminating.  To prove to yourself that this works, set+ x) @0 Z5 A1 A4 ]3 @6 s  H$ {
    the environment variable UGII_KEEP_SYSTEM_LOG=1 so that the syslog will not
# k( M3 d& r! z4 g% f) N8 L$ J    automatically be cleaned up when NX terminates.  Start NX.  Use Help-> NX5 `) f& Q2 _  s. r2 L: O
    Log File and make a note of the full path to the syslog which will be shown
/ v3 x, r: ~1 L, w; d6 j4 B( N4 [3 v. ~    as its own first line.  Run the dll built from this code (nothing noticable# s0 B8 v2 t' c4 B
    will happen.)  Exit NX.  Find the syslog and open it in any text editor to1 P" O( l0 F) J* ?
    see this line near the bottom:- ?+ {, K8 ]: O: d8 n7 B8 g8 }
8 q( d$ l. ]' {9 ?: u8 y8 J. P
NX is shutting down - running ufusr_cleanup
% ~; y! p6 r# y3 E6 w$ [& u. C: Y  x9 Y; O
*/
. Q0 D% R' r6 D& w- P! J#include <stdio.h>
( X7 P; _% v4 t. T: o# P. g#include <string.h>
" r: V7 @3 P% j! _! W+ x: k#include <uf.h>- X9 i/ l8 _5 E
#include <uf_ui.h>
1 s) W3 m9 r+ e0 `$ Y* c#include <uf_exit.h>, |' N  x. z# |* i& a

4 D) g9 L+ P2 ]0 ]#include <stdarg.h>
) w0 T1 m# E4 h4 a* p! z3 i; B$ x) A% f1 c- W' ]0 i% N- F
static void ECHO(char *format, ...)( |0 K; J0 }! a! Z" e
{
( P) d/ ]4 ]( o7 J    char msg[UF_UI_MAX_STRING_LEN+1];  C/ C* l' T  P) K
    va_list args;
- G. c. |/ `4 R: ^" B    va_start(args, format);; I* P' a: X( y& q  [
    vsprintf(msg, format, args);
- K, E/ B' W, y# [- t8 ?    va_end(args);; r7 {6 M2 B3 X3 m
    UF_UI_open_listing_window();3 T3 l' y$ k) ~. H9 a& a
    UF_UI_write_listing_window(msg);/ O" C, R6 k) G" _
    UF_print_syslog(msg, FALSE);
& @) v- g8 s3 X  x2 N}
8 l( t4 x6 X, F/ N4 K/ l
" e2 H  i  e3 k" c7 c/ `$ s#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X))), q" \/ x: g: v5 I1 {

5 H. U+ }7 j9 I; Y  a$ sstatic int report_error( char *file, int line, char *call, int irc)
" c/ `" v, Y$ i* |2 H{- D' O7 \" T* j% b* P; @( Y
    if (irc)
3 j9 g- y6 _7 W! A' O7 o$ m$ t    {7 G; C4 E# y/ n1 l$ Z5 W# V
        char err[133];
6 O" T" S" F# {8 z' U: Y' H( V' f& |+ m6 b
        UF_get_fail_message(irc, err);
. V! n6 \! ~, O7 A        ECHO("*** ERROR code %d at line %d in %s:\n",9 |; Z: {- ^+ K- A$ v2 g
            irc, line, file);
( i  Q, s+ n  O2 c$ Z        ECHO("+++ %s\n", err);
7 y6 H% v$ ~3 Q$ W. v        ECHO("%s;\n", call);
( a/ f; V6 ^/ f+ ~4 a: t# a    }" w" V5 w. N& W) d/ b% G
) C& K5 N5 U9 F, k& c/ h7 @
    return(irc);
9 V. ^( Y) f7 X$ G3 z}
5 Y* {3 x1 b+ F  N! L1 ~" V; g& q' y
/*ARGSUSED*/7 k0 i3 {! C) V. Q6 B; N
void ufusr(char *param, int *reTCode, int paramLen)5 P% ?  H) X( N
{" N7 S9 U$ K1 e/ ]6 H1 B1 @* }
}# r: {9 N, J, Y* ^3 q
  s. X/ j0 U0 H( s" Z8 v4 H2 i
/*ARGSUSED*/
9 A& ^. R! s3 ]: n) p+ Dvoid ufsta(char *param, int *retcode, int paramLen)9 U4 i2 J$ ~& o5 K) A. C
{
! p) _, k; M2 p# B7 {1 L) Y}
* A# b& [# B$ y+ @+ ~
8 D7 j0 M0 Y% `/ a& n; J$ ?int ufusr_ask_unload(void)
# e4 L5 ?0 d! `1 _* h{
& ~7 l& f* E5 z7 F9 x: X+ [    return (UF_UNLOAD_UG_TERMINATE);9 D; O- A: i3 k$ R* x9 D
}
9 {# B* V9 l5 o3 g# Q+ H: g$ i3 e; X* C6 r8 s9 \1 v
void ufusr_cleanup(void)) }- A0 g- t% H5 i4 {. h
{$ c- `2 X$ R) k' N( L/ s8 G% y6 J4 F" L
    ECHO("NX is shutting down - running ufusr_cleanup\n");; d% t) ]$ K; q; ?6 s/ P: m! d
4 z2 h$ t1 z, c% o( @, Y0 B6 z% G
    /* put your code here */
; q: _% |; b3 I+ ?& ]}[/mw_shl_code]
6 g( s- V  F; r* U. X- b" U# }1 N2 M8 b
上海点团信息科技有限公司,承接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
/ m9 ~% ?4 I8 e4 I2 P7 ~+ B) A" B请问这个函数是怎么用的?有什么用?

/ d2 j% M, l  Q( \9 _+ L0 d) V入口函数 改成 ufusr_cleanup
% W0 o- k" a1 H( U% W2 N6 n' t
意思是 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二次开发专题模块培训报名开始啦

    我知道了