版本
NX11+VS2013
几天前有个兄弟在QQ群里问哪个内部函数是切换应用模块的。
关于切换到制图模块,这一块我博客文章写的太多了。几种方法做下来,应该是无论哪个版本的NX,都可以实现切换模块了。
NX二次开发-老版本UG自动切换到制图模块::PostMessage
https://mp.weixin.qq.com/s/iqsapU7wrYSCv_0OxuXtiA
下面讲怎么通过内部函数去实现切换模块
源代码
//NX11_NXOpenCPP_Wizard5 // Mandatory UF Includes #include <uf.h> #include <uf_object_types.h> // Internal Includes #include <NXOpen/ListingWindow.hxx> #include <NXOpen/NXMessageBox.hxx> #include <NXOpen/UI.hxx> // Internal+External Includes #include <NXOpen/Annotations.hxx> #include <NXOpen/Assemblies_Component.hxx> #include <NXOpen/Assemblies_ComponentAssembly.hxx> #include <NXOpen/Body.hxx> #include <NXOpen/BodyCollection.hxx> #include <NXOpen/Face.hxx> #include <NXOpen/Line.hxx> #include <NXOpen/NXException.hxx> #include <NXOpen/NXObject.hxx> #include <NXOpen/Part.hxx> #include <NXOpen/PartCollection.hxx> #include <NXOpen/Session.hxx> #include <uf.h> #include <uf_ui.h> #include <uf_mb.h> #include <afx.h> // Std C++ Includes #include <iostream> #include <sstream> using namespace NXOpen; using std::string; using std::exception; using std::stringstream; using std::endl; using std::cout; using std::cerr; //------------------------------------------------------------------------------ // 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: Part *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()->Work(); displayPart = theSession->Parts()->Display(); } //------------------------------------------------------------------------------ // 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 UF_initialize(); //调内部函数切换应用模块 typedef void(*load_ufusr_f_p_t)(char const *v1);//定义传参 load_ufusr_f_p_t UI_APP_change_application = NULL; UF_load_library("C:\\Program Files\\Siemens\\NX 11.0\\NXBIN\\libugui.dll", "?UI_APP_change_application@@YAHPEBD@Z", (UF_load_f_p_t *)&UI_APP_change_application); if (UI_APP_change_application != NULL) { UI_APP_change_application("UG_APP_DRAFTING"); } UF_terminate(); } //------------------------------------------------------------------------------ // 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 MyClass *theMyClass; theMyClass = new MyClass(); theMyClass->do_it(); delete theMyClass; } 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; }
演示
//调内部函数获取当前模块名称
源代码
UF_initialize(); //调内部函数获取当前模块名称 typedef char *(*load_ufusr_f_p_t)(void);//定义传参 load_ufusr_f_p_t MT_get_appname = NULL; UF_load_library("C:\\Program Files\\Siemens\\NX 11.0\\NXBIN\\libugui.dll", "?MT_get_appname@@YAPEADXZ", (UF_load_f_p_t *)&MT_get_appname); if (MT_get_appname != NULL) { char * res = MT_get_appname(); uc1601(res, 1); } UF_terminate();
演示
阿飞
2021你拿9月4日
NX二次开发-调内部函数UI_APP_change_application切换到制图模块
原文:https://www.cnblogs.com/nxopen2018/p/15222551.html