C#实现单个DLL调用多个功能,根据主入口参数调用不同功能
正常NX二次开发时,我们一般都是Ctrl+U直接执行的,但实际NX也给我们预留了一个输入参数
- 我们可以通过这个进行传参,达到一个DLL调用不同功能的效果!
实践
- 块样式编辑器创建如下两个界面
Windows1.dlx
Windows2.dlx
手写主入口
- 以下是完整的主入口
public static int Main(string[] args)
{
int retValue = 0;
try
{
theProgram = new Program();
//在这里写实现
if (args[0] == "w1")
{
Windows1 theWindows1 = null;
try
{
theWindows1 = new Windows1();
// The following method shows the dialog immediately
theWindows1.Show();
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
finally
{
if (theWindows1 != null)
theWindows1.Dispose();
theWindows1 = null;
}
}
else if (args[0] == "w2")
{
Windows2 theWindows2 = null;
try
{
theWindows2 = new Windows2();
// The following method shows the dialog immediately
theWindows2.Show();
}
catch (Exception ex)
{
//---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString());
}
finally
{
if (theWindows2 != null)
theWindows2.Dispose();
theWindows2 = null;
}
}
else if(args[0] == "")
{
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error,"没有定义调用窗口!请传参!");
}
theProgram.Dispose();
}
catch (NXOpen.NXException ex)
{
// ---- Enter your exception handling code here -----
}
return retValue;
}
效果展示
这个例子演示了,传入不同的参数启动不同的功能界面,且人为启动时,不执行任何操作
理论上来说,不告诉使用者入口的名称,使用者就没法使用这个功能!
菜单写法
- 首先这个是支持从men启动的,写法如下
BUTTON w1
LABEL 第一个界面
BITMAP
ACTIONS D:\Windows.dll
BUTTON w2
LABEL 第一个界面
BITMAP
ACTIONS D:\Windows.dll