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

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

  [复制链接]

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

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

admin 楼主

2018-7-12 11:12:47

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

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

x

- J+ y- }+ ^/ F/ n6 e8 WNX二次开发源码分享】关闭NX后,做点儿事
3 _7 C6 R- ]  b+ I# p4 X/ \
6 D$ v* E5 ~* x+ U" q[mw_shl_code=c,true]/*+ V  g2 u) W+ {$ N% U. C

0 V# V$ c  V6 t" v+ J8 B' u1 j: n    ufusr_ask_unload is invoked immediately following the completion of ufusr6 p. z  C7 Q+ N5 G9 l/ b# ^/ Q) c5 e
    (or ufsta when the dll is run from a startup folder) to find out when you
- h, e# O5 o( k. L1 l0 y9 G    want the dll to be unloaded.  If ufusr_ask_unload returns
& v# R$ \/ D& ?: R" A  v/ D    UF_UNLOAD_UG_TERMINATE, the ufusr_cleanup is called right before the dll is
: G& j& c, p4 S1 M    unload when NX is terminating.  To prove to yourself that this works, set
+ X: F0 _  |8 W$ K* X1 `    the environment variable UGII_KEEP_SYSTEM_LOG=1 so that the syslog will not
" g( o' e( U# Z/ `+ X. Z    automatically be cleaned up when NX terminates.  Start NX.  Use Help-> NX1 \+ S* _6 l  w1 P; T- N
    Log File and make a note of the full path to the syslog which will be shown
" [- G3 }% \4 D! H" d( ?( |    as its own first line.  Run the dll built from this code (nothing noticable1 q* J. \/ `! X5 j2 T
    will happen.)  Exit NX.  Find the syslog and open it in any text editor to
8 p1 p3 q2 F* Z: t, S$ g  x  @# N    see this line near the bottom:
* D2 Q+ L/ l4 [* l! e5 s7 `% _4 L- Z
NX is shutting down - running ufusr_cleanup; |' L" v6 J  f0 [$ b/ \) R
9 |' g& ]7 _' _. o4 H; \1 D
*/$ U5 c/ P8 O* x% g  Q
#include <stdio.h>* `. ^9 v. }- X
#include <string.h>! {( l, @; I& H2 ]2 y
#include <uf.h>
/ S( o% C; O3 l0 }2 P/ t#include <uf_ui.h>
: x, k- Y3 n# c+ L4 {2 @#include <uf_exit.h>
3 p, M& _' t! J. ]" y/ q  Z
. [2 k4 b2 e1 q6 r/ I6 X#include <stdarg.h>7 I6 r: \1 B; P, i3 ~' R
7 |8 U; g- L5 s) [8 r9 q, k
static void ECHO(char *format, ...)# ]9 v1 h( D  b% _& W
{
7 T6 W: C! y0 ]2 D    char msg[UF_UI_MAX_STRING_LEN+1];" [6 `0 v% q8 X3 d) _" a
    va_list args;, `! O4 d! W; |, `
    va_start(args, format);
. N( W$ f* x+ J/ J    vsprintf(msg, format, args);9 q2 x3 b, T: F3 C- a* I
    va_end(args);
4 @5 M* M. X, k3 |    UF_UI_open_listing_window();
* k% m5 Q9 ~! U/ t    UF_UI_write_listing_window(msg);
  B  m& h3 h7 T4 F/ S    UF_print_syslog(msg, FALSE);
( x: r* b% }+ v6 c- C}( L7 U  R6 P. q) A5 ]

) Z+ I; {. j* C) w4 V* X8 [1 s#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))# s! ^. T3 S2 {. ]# O4 r( T

8 |+ p- O2 {$ B7 F! [- Dstatic int report_error( char *file, int line, char *call, int irc)
# Z  F1 d+ ]& W" D{
7 h  T% G8 b6 D: q    if (irc)
/ q  s- z1 A2 R1 [3 ~. e# p    {$ a' C! k% J6 t0 c" E4 c9 {
        char err[133];
6 `9 T4 l; j6 p( G% b
1 a) K* c# p+ [: ?! g2 h8 p        UF_get_fail_message(irc, err);
3 W/ R; M. x' @( U9 X4 L        ECHO("*** ERROR code %d at line %d in %s:\n",7 E+ e6 w: F' h
            irc, line, file);" Y  c1 W* |; b1 R9 Z* k
        ECHO("+++ %s\n", err);
7 L0 D* M9 T4 o3 Z        ECHO("%s;\n", call);
" t+ j/ @, y5 [1 h* W+ Z  |* Y    }/ k* P% J" w8 @% |) J
( a; C" U! ~8 O: m4 |7 S+ [
    return(irc);
, Q; T! c( W, Y3 U' _}
4 ^- Z8 d9 _) J( `: c6 r
. O0 O- _- O+ X  j3 ^% w6 D& p/*ARGSUSED*/8 t- }7 O3 ]1 v/ o3 J( z
void ufusr(char *param, int *reTCode, int paramLen)- l& f+ A9 ]0 Z6 O
{# c) a1 W1 k  G4 _9 s4 B, ?- e
}
$ P% g/ p0 b/ {
. P* j' C' K- Q) s1 Q/*ARGSUSED*/
% s7 c( z6 r4 Uvoid ufsta(char *param, int *retcode, int paramLen)- G& R( f/ n& l& k
{
7 s5 G0 Y3 p) a" s8 B% u}" l& t- _4 f) E1 \$ [' ~
: n0 O+ O" N' t: @9 @
int ufusr_ask_unload(void)5 y/ R- N$ F" Z7 [+ E
{
5 T/ r! x* S9 M0 @+ ?. H    return (UF_UNLOAD_UG_TERMINATE);0 t; l# g4 W+ m. D8 R
}
' I& `5 k, x+ ^  ^; f, y) H) K0 B, E0 s+ ?
void ufusr_cleanup(void)2 g& d; N$ K; E# {! f5 V0 N: F
{
8 z1 y1 f; V* ~' J  A0 p; Y$ Y    ECHO("NX is shutting down - running ufusr_cleanup\n");
$ P2 f# z! B# u" z0 C6 O4 M2 x' B1 p" h; e. }2 p7 ?0 w3 |
    /* put your code here */, w: V4 r9 F* l- b4 b9 }
}[/mw_shl_code]
" {& {. B& t1 H, l( {3 P2 N8 |
上海点团信息科技有限公司,承接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
& p$ M7 Y; E  ?( _请问这个函数是怎么用的?有什么用?

+ ^0 Q, U% m7 P) `( G- q入口函数 改成 ufusr_cleanup
, H1 n8 ~5 B) Z, J* ~3 ]5 G7 V/ h" w& t7 @# g& }, 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二次开发专题模块培训报名开始啦

    我知道了