嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
aotu cad二次开发不用多次启动cad的好用小程序
1.小程序可以解决,调试中或者二次开发中,多次启动aotu cad的问题
2.小程序是通过动态加载目标dll,通过反射来完成加载
1.新建一个类库LoadX,class名也改成LoadX,不改也行
2.LoadX的代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace LoadX
{
public class LoadX
{
private Action cmd;
[CommandMethod("DD")]
public void LoadDD() {
CmdInfo info = LoadCmdInfo();
#region 不用动
var adapterFileInfo = new FileInfo(Assembly.GetExecutingAssembly().Location);
var targetFilePath = Path.Combine(adapterFileInfo.DirectoryName, info.DllName);
var targetAssembly = Assembly.Load(File.ReadAllBytes(targetFilePath));
var targetType = targetAssembly.GetType(info.ClassName);
var targetMethod = targetType.GetMethod(info.MethodName);
var targetObject = Activator.CreateInstance(targetType);
cmd = () => targetMethod.Invoke(targetObject, null);
try
{
cmd.Invoke();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "tips");
}
#endregion
}
public CmdInfo LoadCmdInfo() {
CmdInfo cmd = new CmdInfo();
string jsonFile = @"E:\cmd.json";
using (StreamReader file = File.OpenText(jsonFile))
{
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject o = (JObject)JObject.ReadFrom(reader);
cmd.DllName = o["DllName"].ToString();
cmd.ClassName = o["ClassName"].ToString();
cmd.MethodName = o["MethodName"].ToString();
}
}
return cmd;
}
}
public class CmdInfo
{
public string DllName { get; set; }
public string ClassName { get; set; }
public string MethodName { get; set; }
}
}
3.外部json文件,可以存放在固定的盘符,如:E:\cmd.json,内容:
{
"DllName": "CmdDemo.dll",
"ClassName": "CmdDemo.Cmd",
"MethodName": "CmdSum"
}
4.正常写目标dll中class对应的cmd,如CmdDemo类库中的Cmd类文件中的CmdSum命令:
[CommandMethod("CmdSum")]
public void CmdSum()
{
int sum = 0;
int max = 10;
for (int i = 1; i < max; i )
{
sum = i;
}
double d = 13;
double d2 = sum / d;
System.Windows.Forms.MessageBox.Show(sum.ToString() "\n" d2 "info(Tips)");
}
5.目标CmdDemo类库的生成dll的路径,改为LoadX的生成dll的路径,如:
6.配置好之后,先关闭aotu cad,重新生成解决方案,把两个类库都生成成功
7.开启aotu cad,输入命令netload,选择LoadX.dll,输入命令DD,即可看到效果
8.如果要修改目标类库中对应的命令,如修改CmdSum中的值,修改后,点击生成当前类库,不能重新生成解决方案,此时不需要重新生成LoadX,如果强行生成LoadX,则会报错,解决错误的方式是关闭aotu cad,所以这里不要再生成LoadX类库
9.多试几次,胜利的曙光就在眼前
.
├── AotuAcdDemo
│ ├── AotuCADDemo.sln
│ ├── CmdDemo
│ │ ├── Cmd.cs
│ │ ├── CmdDemo.csproj
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ ├── bin
│ │ │ ├── Debug
│ │ │ └── Release
│ │ └── obj
│ │ └── Debug
│ │ ├── CmdDemo.csproj.AssemblyReference.cache
│ │ ├── CmdDemo.csproj.CoreCompileInputs.cache
│ │ ├── CmdDemo.csproj.FileListAbsolute.txt
│ │ ├── CmdDemo.dll
│ │ ├── CmdDemo.pdb
│ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ └── TempPE
│ ├── LoadX
│ │ ├── LoadX.cs
│ │ ├── LoadX.csproj
│ │ ├── Properties
│ │ │ └── AssemblyInfo.cs
│ │ ├── bin
│ │ │ ├── Debug
│ │ │ │ ├── CmdDemo.dll
│ │ │ │ ├── CmdDemo.pdb
│ │ │ │ ├── LoadX.dll
│ │ │ │ ├── LoadX.pdb
│ │ │ │ ├── Newtonsoft.Json.dll
│ │ │ │ └── Newtonsoft.Json.xml
│ │ │ └── Release
│ │ ├── obj
│ │ │ └── Debug
│ │ │ ├── DesignTimeResolveAssemblyReferencesInput.cache
│ │ │ ├── LoadX.csproj.AssemblyReference.cache
│ │ │ ├── LoadX.csproj.CopyComplete
│ │ │ ├── LoadX.csproj.CoreCompileInputs.cache
│ │ │ ├── LoadX.csproj.FileListAbsolute.txt
│ │ │ ├── LoadX.dll
│ │ │ ├── LoadX.pdb
│ │ │ └── TempPE
│ │ └── packages.config
│ └── packages
│ └── Newtonsoft.Json.13.0.1
│ ├── LICENSE.md
│ ├── Newtonsoft.Json.13.0.1.nupkg
│ ├── lib
│ │ ├── net20
│ │ │ ├── Newtonsoft.Json.dll
│ │ │ └── Newtonsoft.Json.xml
│ │ ├── net35
│ │ │ ├── Newtonsoft.Json.dll
│ │ │ └── Newtonsoft.Json.xml
│ │ ├── net40
│ │ │ ├── Newtonsoft.Json.dll
│ │ │ └── Newtonsoft.Json.xml
│ │ ├── net45
│ │ │ ├── Newtonsoft.Json.dll
│ │ │ └── Newtonsoft.Json.xml
│ │ ├── netstandard1.0
│ │ │ ├── Newtonsoft.Json.dll
│ │ │ └── Newtonsoft.Json.xml
│ │ ├── netstandard1.3
│ │ │ ├── Newtonsoft.Json.dll
│ │ │ └── Newtonsoft.Json.xml
│ │ └── netstandard2.0
│ │ ├── Newtonsoft.Json.dll
│ │ └── Newtonsoft.Json.xml
│ └── packageIcon.png
└── aotu cad二次开发不用多次启动cad的好用小程序_AotuAcdDemo.zip
27 directories, 45 files