After the AutoCAD .NET Addin Wizard (AcadNetAddinWizard) is installed, the AutoCAD .NET Addin template will be added to the Visual Studio IDE of various full-fledged editions or Express, 2008 or 2010, C#, VB.NET or C++/CLI.
When creating or adding a new C# project in Visual C# 2008 Express, choose the AutoCAD .NET Addin from the Templates list view of the New Project dialog, and provide a project name and location:
The following AutoCAD .NET Addin Wizard pages will show up one after another:
Here is the application extension class created automatically by the wizard into the project:
#region Namespaces
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Windows;
using MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using MgdAcDocument = Autodesk.AutoCAD.ApplicationServices.Document;
using AcWindowsNS = Autodesk.AutoCAD.Windows;
#endregion
namespace AcadNetAddinCS1
{
public class ExtApp : IExtensionApplication
{
#region IExtensionApplication Members
public void Initialize()
{
//TODO: add code to run when the ExtApp initializes. Here are a few examples:
// Checking some host information like build #, a patch or a particular Arx/Dbx/Dll;
// Creating/Opening some files to use in the whole life of the assembly, e.g. logs;
// Adding some ribbon tabs, panels, and/or buttons, when necessary;
// Loading some dependents explicitly which are not taken care of automatically;
// Subscribing to some events which are important for the whole session;
// Etc.
}
public void Terminate()
{
//TODO: add code to clean up things when the ExtApp terminates. For example:
// Closing the log files;
// Deleting the custom ribbon tabs/panels/buttons;
// Unloading those dependents;
// Un-subscribing to those events;
// Etc.
}
#endregion
}
}
Here is the command method class created automatically by the wizard into the project:
#region Namespaces
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Windows;
using MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using MgdAcDocument = Autodesk.AutoCAD.ApplicationServices.Document;
using AcWindowsNS = Autodesk.AutoCAD.Windows;
#endregion
namespace AcadNetAddinCS1
{
public class CmdGroup1
{
[CommandMethod("CmdGroup1", "Command1", null, CommandFlags.Modal, null, "AcadNetAddinCS1", "Command1")]
public void Command1_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//TODO: add your code below.
Debug.WriteLine("Command1 ran.");
ed.WriteMessage("Command1 ran.\n");
tr.Commit();
}
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
}
}
As mentioned before, in order to debug or even load the AutoCAD .NET assemblies compiled with .NET 3.5 or earlier, we have to tweak the acad.exe.config file to make that happen. Otherwise, the following “The debugger’s protocol is incompatible with the debugger.” Error message will pop up if we press the F5 right after the project being created to try to debug the addin.
After the acad.exe.config file being tweaked as introduced before, we can debug the addin from window the Visual Studio C# 2008 Express without doing anything more. Give it a try and you will not miss it.
The leading edge AcadNetAddinWizard can help create various AutoCAD .NET Addin projects (C#, VB.NET and C++/CLI) in Visual Studio 2008 and 2010 either full-fledged or Express.
Recent Comments