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. 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.
Tried different codes from other sources and still no results Should I use a higher version of AutoCad? or should I use a lower version of VS like 2017? 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?