【NX二次开发】C#实现单个DLL调用多个功能,根据主入口参数调用不同功能

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值