NX二次开发:一个DLL设置多个按钮操作的方法

发布时间 2023-03-29 17:09:00作者: huangym1

还有很多人不知道如何设置一个DLL调用不同的功能,今天说的是通过入口函数参数值进行设置。还有一种方法是使用UF_MB.h里面的函数也可以实现,今天先说一种,具体看代码。

  1 //=============================
  2 // 一个DLL设置多个按钮操作的方法
  3 //=============================
  4 // Mandatory UF Includes
  5 #include <uf.h>
  6 #include <uf_object_types.h>
  7 #include <uf_draw.h>
  8 #include <uf_part.h>
  9 #include <uf_ugmgr.h>
 10 #include <uf_ui.h>
 11 #include <uf_obj.h>
 12 #include <uf_drf.h>
 13 
 14 // Std C++ Includes
 15 #include <iostream>
 16 #include <sstream>
 17 #include <vector>
 18 #include <string>
 19 #include <algorithm>
 20 #include <tchar.h>
 21 #include <atlconv.h>
 22 #include <shellapi.h>
 23 
 24 #include <windows.h>
 25 #undef CreateDialog
 26 #pragma comment(lib,"shell32.lib")
 27 
 28 using namespace NXOpen;
 29 using std::string;
 30 using std::exception;
 31 using std::stringstream;
 32 using std::endl;
 33 using std::cout;
 34 using std::cerr;
 35 
 36 static enum StringValue {
 37     evNotDefined,
 38     evStringValue1,
 39     evStringValue2,
 40     evStringValue3,
 41     evStringEnd
 42 };
 43 static std::map<std::string, StringValue> s_mapStringValues;
 44 static void Initialize()
 45 {
 46     s_mapStringValues["HNMDL_TOOL251"] = evStringValue1;
 47     s_mapStringValues["HNMDL_TOOL252"] = evStringValue2;
 48     s_mapStringValues["HNMDL_TOOL253"] = evStringValue3;
 49     s_mapStringValues["end"] = evStringEnd;
 50 
 51     cout << "s_mapStringValues contains " << s_mapStringValues.size() << " entries." << endl;
 52 }
 53 
 54 
 55 extern "C" DllExport void ufusr( char *parm, int *returnCode, int rlen )
 56 {
 57     try
 58     {
 59         UF_CALL(UF_initialize());
 60 
 61         Initialize();
 62 
 63         switch (s_mapStringValues[parm])
 64         {
 65         case evStringValue1:
 66             uc1601(parm, 1);
 67             // 其他操作
 68             break;
 69         case evStringValue2:
 70             uc1601(parm, 1);
 71             // 其他操作
 72             break;
 73         case evStringValue3:
 74             uc1601(parm, 1);
 75             // 其他操作
 76             break;
 77         default:
 78             uc1601(parm, 1);
 79             // 其他操作
 80             break;
 81         }
 82 
 83         UF_CALL(UF_terminate());
 84     }
 85     catch (const NXException& e1)
 86     {
 87         UI::GetUI()->NXMessageBox()->Show("NXException", NXOpen::NXMessageBox::DialogTypeError, e1.Message());
 88     }
 89     catch (const exception& e2)
 90     {
 91         UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, e2.what());
 92     }
 93     catch (...)
 94     {
 95         UI::GetUI()->NXMessageBox()->Show("Exception", NXOpen::NXMessageBox::DialogTypeError, "Unknown Exception.");
 96     }
 97 }
 98 
 99 extern "C" DllExport int ufusr_ask_unload()
100 {
101     return (int)NXOpen::Session::LibraryUnloadOptionImmediately;// 调试用
102     //return (int)NXOpen::Session::LibraryUnloadOptionAtTermination;// 程序发布用
103     //return (int)NXOpen::Session::LibraryUnloadOptionExplicitly;
104 }

 

相关简介及函数截图:

 

GIF动图:

 

黄河远上白云间,一片孤城万仞山。
羌笛何须怨杨柳,春风不度玉门关。

诗人初到凉州,面对黄河、边城的辽阔景象,又耳听着《折杨柳》曲,有感而发,写成了这首表现戍守边疆的士兵思念家乡情怀的诗作。

  诗的前两句描绘了西北边地广漠壮阔的风光。首句抓住自下(游)向上(游)、由近及远眺望黄河的特殊感受,描绘出“黄河远上白云间”的动人画面:汹涌澎湃波浪滔滔的黄河竟像一条丝带迤逦飞上云端。写得真是神思飞跃,气象开阔。诗人的另一名句“黄河入海流”,其观察角度与此正好相反,是自上而下的目送;而李白的“黄河之水天上来”,虽也写观望上游,但视线运动却又由远及近,与此句不同。“黄河入海流”和“黄河之水天上来”,同是着意渲染黄河一泻千里的气派,表现的是动态美。而“黄河远上白云间”,方向与河的流向相反,意在突出其源远流长的闲远仪态,表现的是一种静态美。同时展示了边地广漠壮阔的风光,不愧为千古奇句。