我正在尝试使用.Net为带有Visual Studio 2019的Autocad 2018插件首先,当调试为“ Any CPU”时,我在VS中收到警告,当我切换到x64时,该错误消失了。生成项目并获取.dll文件后,我转到Autocad并使用NETLOAD命令加载该文件,当我尝试加载我的方法或“ CommandMethod”时,它没有显示。
尝试使用其他来源的不同代码,但仍然没有结果我应该使用更高版本的AutoCad吗?还是应该使用较低版本的VS,例如2017?可能是什么问题呢?这是代码:
使用系统;使用Autodesk.AutoCAD.ApplicationServices;使用Autodesk.AutoCAD.DatabaseServices;使用Autodesk.AutoCAD.Geometry;使用Autodesk.AutoCAD.EditorInput;使用Autodesk.AutoCAD.Runtime;使用Autodesk.AutoCAD.ApplicationServices.Core;
[[assembly:CommandClass(typeof(Testing.Class1))]命名空间测试{公共课Class1{[CommandMethod(“ MyFirstCommand”)]公共无效my(){
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor edt = doc.Editor;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
try
{
BlockTable bt;
bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr;
btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
// send message to the user
edt.WriteMessage("\nDrawing a line objet");
Point3d pt1 = new Point3d(0, 0, 0);
Point3d pt2 = new Point3d(100, 0, 0);
Line ln = new Line(pt1, pt2);
ln.ColorIndex = 1;
btr.AppendEntity(ln);
trans.AddNewlyCreatedDBObject(ln, true);
trans.Commit();
}
catch (System.Exception e)
{
edt.WriteMessage("Error Encountered" + e.Message);
trans.Abort();
}
}
edt.WriteMessage("Script loaded");
}
}
}
在此处输入代码
public