简体   繁体   English

Autocad 2018 NETLOAD 未显示我的命令方法

[英]Autocad 2018 NETLOAD not showing my command method

I'm trying to make a plug in for Autocad 2018 with Visual Studio 2019 using .Net Firstly, I am getting a warning in VS when the debug is "Any CPU" the bug goes off when I switch to x64.我正在尝试使用 .Net 使用 Visual Studio 2019 为 Autocad 2018 制作插件首先,当调试为“任何 CPU”时,我在 VS 中收到警告,当我切换到 x64 时,错误消失。 After building the project and having the .dll file and I go to Autocad and load it using NETLOAD command, when I try to load my method or "CommandMethod" it doesn't show up.构建项目并拥有 .dll 文件后,我转到 Autocad 并使用 NETLOAD 命令加载它,当我尝试加载我的方法或“CommandMethod”时,它没有显示。

  • I tried changing the .Net Framework to whatever version I have from 4.7.2 to 4.5我尝试将 .Net Framework 更改为从 4.7.2 到 4.5 的任何版本
  • Tried different codes from other sources and still no results Should I use a higher version of AutoCad?尝试了其他来源的不同代码,但仍然没有结果 我应该使用更高版本的 AutoCad 吗? or should I use a lower version of VS like 2017?或者我应该使用像 2017 这样的较低版本的 VS? What could be the problem?可能是什么问题呢? Here's the code:这是代码:

     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"); } }

    } }

Check your references.检查您的参考资料。 I have had problems with this in the past when I have a broken or incorrect reference.过去,当我的参考资料损坏或不正确时,我遇到了这个问题。

Are any of your settings for your AutoCAD references different than the settings in the below image?您的 AutoCAD 参考设置是否与下图中的设置不同?

AutoCAD 参考特性窗口

Waseememe wrote: Wasememe 写道:

SOLVED by adding the dll files from ObjecrARX folder called "inc" I had older versions of the dll files which they weren't compatible with AutoCad 2018, thanks !通过添加名为“inc”的 ObjecrARX 文件夹中的 dll 文件解决了我有旧版本的 dll 文件,它们与 AutoCad 2018 不兼容,谢谢! – Waseememe Feb 18 at 22:38 – Wasememe 2 月 18 日 22:38

As I cannot add any comments ill add this as an answer.由于我无法添加任何评论,因此将其添加为答案。

You should really add your references through the NuGet packages functionality built into Visual Studio.您确实应该通过 Visual Studio 中内置的 NuGet 包功能添加您的引用。 This will resolve any future problems related to this.这将解决与此相关的任何未来问题。

How?如何? -→ https://docs.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio tldr: right click your project, click on manage NuGet packages, click the "Browse" tab, and search for the AutoCAD API packages, install them by using the UI to the right. -→ https://docs.microsoft.com/en-us/nuget/quickstart/install-and-use-a-package-in-visual-studio tldr:右键单击您的项目,单击管理 NuGet 包,单击“浏览”选项卡,然后搜索 AutoCAD API 包,使用右侧的 UI 安装它们。

管理nuget包 界面右侧

Where is the AutoCAD NuGet located on the net? AutoCAD NuGet 在网上的什么位置? -→ https://www.nuget.org/packages/AutoCAD.NET/23.1.0/ -→ https://www.nuget.org/packages/AutoCAD.NET/23.1.0/

您定义[CommandMethod("Command_Name")]必须是public

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM