【发布时间】:2020-06-02 08:45:27
【问题描述】:
我正在尝试使用 .Net 为 Autocad 2018 和 Visual Studio 2019 制作插件 首先,当调试为“任何 CPU”时,我在 VS 中收到警告,当我切换到 x64 时,该错误就会消失。 在构建项目并拥有 .dll 文件后,我转到 Autocad 并使用 NETLOAD 命令加载它,当我尝试加载我的方法或“CommandMethod”时,它没有显示出来。
- 我尝试将 .Net Framework 更改为我拥有的任何版本,从 4.7.2 到 4.5
-
尝试了其他来源的不同代码,但仍然没有结果 我应该使用更高版本的 AutoCad 吗?还是我应该使用 2017 等较低版本的 VS? 可能是什么问题呢? 代码如下:
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices.Core; [assembly: CommandClass(typeof(Testing.Class1))] namespace Testing { public class Class1 { [CommandMethod("MyFirstCommand")] public void 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"); } }}
【问题讨论】:
标签: c# .net autocad autocad-plugin