I'm developing some AutoCAD add-ons in C# and I was hoping to work/debug my classes in a console application first until I'm ready to implement the functionality inside AutoCAD. /dot net libraries cannot be unloaded and one needs to restart/reload acad each time the code is modified/ Interestingly I'm finding that as soon as I declare a variable which uses an autocad data type my console app refuses to run and Im presented with a "the application is in break mode" screen in visual studio. For example this code does not run:
using System;
using Autodesk.AutoCAD.Geometry;
namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hi");
Point2d p;
Console.ReadKey();
}
}
}
Trying this referencing Autodesk C3D 2016 dll libraries. Does anyone have an explanation of what is going on here and/or any workarounds? thnks
The AutoCAD .NET API is designed to run in-process only. AutoCAD .NET libraries can only be used to build plug-ins (DLL) which have to be loaded in AutoCAD for execution.
To debug your AutoCAD Add-On code, you need to create a C# Class Library Project referencing the Autodesk CAD 2016 Sdk Libraries, and encapsulate your code on public method that declared with CommandMethodAttribute. With this method declared with CommandMethod it's the be your trigger between the AutoCAD prompt command and your Add-On code.
Note: at your Visual Studio Project Properties, you need to configure to start debug pointed to acad.exe and when the AutoCAD applications starts, open some DWG and prompt the "NETLOAD" command to include your debbugable compiled DLL from your VS Project to AutoCAD Application context.