NX二次开发-UFUN结合NXOPEN开发_常用代码模板

hpp

 1 //头文件
 2 #include <NXOpen/Part.hxx>
 3 #include <NXOpen/PartCollection.hxx>
 4 #include <NXOpen/Session.hxx>
 5 #include <NXOpen/ListingWindow.hxx>
 6 #include <NXOpen/NXMessageBox.hxx>
 7 #include <NXOpen/UI.hxx>
 8 #include <stdarg.h>
 9 #include <strstream>
10 #include <iostream>
11 
12 using namespace NXOpen;
13 using namespace std;
14 public:
15     static Session *theSession;
16     static UI *theUI;
17     void print(const NXString &);
18     void print(const string &);
19     void print(const char*);
20 
21 private:
22     Part *workPart, *displayPart;
23     NXMessageBox *mb;
24     ListingWindow *lw;
25     LogFile *lf;

cpp

 1 //使用UF_CALL
 2 static void ECHO(char *format, ...)
 3 {
 4     char msg[UF_UI_MAX_STRING_BUFSIZE];
 5     va_list args;
 6     va_start(args, format);
 7     vsnprintf_s(msg, sizeof(msg), _TRUNCATE, format, args);
 8     va_end(args);
 9     UF_UI_open_listing_window();
10     UF_UI_write_listing_window(msg);
11     UF_print_syslog(msg, FALSE);
12 }
13 
14 #define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
15 
16 static int report_error(char *file, int line, char *call, int irc)
17 {
18     if (irc)
19     {
20         char err[133];
21 
22         UF_get_fail_message(irc, err);
23         ECHO("*** ERROR code %d at line %d in %s:
",
24             irc, line, file);
25         ECHO("+++ %s
", err);
26         ECHO("%s;
", call);
27     }
28 
29     return(irc);
30 }
31 
32 
33 构造函数()
34         mb = theUI->NXMessageBox();
35         lw = theSession->ListingWindow();
36         lf = theSession->LogFile();
37         workPart = theSession->Parts()->Work();
38         displayPart = theSession->Parts()->Display();
原文地址:https://www.cnblogs.com/nxopen2018/p/11876256.html