// Mandatory UF Includes
#include <uf.h>
#include <uf_modl.h>
#include <uf_obj.h>
#include <uf_eval.h>
#include <uf_ui.h>
#include <uf_object_types.h>
// Internal Includes
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Session.hxx>
// Std C++ Includes
using namespace NXOpen;
using std::string;
using std::exception;
using std::stringstream;
using std::endl;
//------------------------------------------------------------------------------
// NXOpen c++ test class
//------------------------------------------------------------------------------
class MyClass
{
// class members
public:
static Session *theSession;
static UI *theUI;
MyClass();
~MyClass();
void do_it();
void print(const NXString &);
void print(const string &);
void print(const char*);
private:
BasePart *workPart, *displayPart;
NXMessageBox *mb;
ListingWindow *lw;
LogFile *lf;
};
//------------------------------------------------------------------------------
// Initialize static variables
//------------------------------------------------------------------------------
Session *(MyClass::theSession) = NULL;
UI *(MyClass::theUI) = NULL;
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
MyClass::MyClass()
{
// Initialize the NX Open C++ API environment
MyClass::theSession = NXOpen::Session::GetSession();
MyClass::theUI = UI::GetUI();
mb = theUI->NXMessageBox();
lw = theSession->ListingWindow();
lf = theSession->LogFile();
workPart = theSession->Parts()->BaseWork();
displayPart = theSession->Parts()->BaseDisplay();
}
//------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------
MyClass::~MyClass()
{
}
//------------------------------------------------------------------------------
// Print string to listing window or stdout
//------------------------------------------------------------------------------
void MyClass::print(const NXString &msg)
{
if(! lw->IsOpen() ) lw->Open();
lw->WriteLine(msg);
}
void MyClass::print(const string &msg)
{
if(! lw->IsOpen() ) lw->Open();
lw->WriteLine(msg);
}
void MyClass::print(const char * msg)
{
if(! lw->IsOpen() ) lw->Open();
lw->WriteLine(msg);
}
//------------------------------------------------------------------------------
// Do something
//------------------------------------------------------------------------------
void MyClass::do_it()
{
// TODO: add your code here
UI *theUI = UI::GetUI();
NXMessageBox *msgBox;
msgBox = theUI->NXMessageBox();
msgBox->Show("弹框标题", NXOpen::NXMessageBox::DialogTypeError, "弹框内容");//错误
msgBox->Show("弹框标题", NXOpen::NXMessageBox::DialogTypeWarning, "弹框内容");//警告
msgBox->Show("弹框标题", NXOpen::NXMessageBox::DialogTypeInformation, "弹框内容");//信息
uc1601("弹框内容", 1);//与msgBox->Show("弹框标题", NXOpen::NXMessageBox::DialogTypeInformation, "弹框内容");相同
}
//------------------------------------------------------------------------------
// Entry point(s) for unmanaged internal NXOpen C/C++ programs
//------------------------------------------------------------------------------
// Explicit Execution
extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
try
{
// Create NXOpen C++ class instance
UF_initialize();
MyClass *theMyClass;
theMyClass = new MyClass();
theMyClass->do_it();
delete theMyClass;
UF_terminate();
}
catch (const NXException& e1)
{
UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
}
catch (const exception& e2)
{
UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
}
catch (...)
{
UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");
}
}
//------------------------------------------------------------------------------
// Unload Handler
//------------------------------------------------------------------------------
extern "C" DllExport int ufusr_ask_unload()
{
return (int)NXOpen::Session::LibraryUnloadOptionImmediately;
}
![]()