After the AutoCAD .NET Addin Wizard (AcadNetAddinWizard) is installed, the AutoCAD .NET Addin templates will be added to the Visual Studio IDE of various full-fledged and Express editions, 2008 and 2010 versions, C#, VB.NET and C++/CLI languages.
But the AutoCAD .NET Addin Wizard (AcadNetAddinWizard) is far more than just some templates scattered around. It is a real-wizard-sense wizard, i.e. multi paged, configurable, flexible, and intelligent. From now on, let us see how the AutoCAD .NET Addin Wizard (AcadNetAddinWizard) can help us create cool AutoCAD .NET addin projects in different languages with IDEs of different editions and versions.
When creating or adding a new C# project in Visual Studio 2008, choose the second Visual C# node and the AutoCAD .NET Addin template, and provide project name and location:
AutoCAD .NET Addin Template of C# Project in Visual Studio 2008
The following wizard welcome page will show up:
AutoCAD .NET Addin Wizard (AcadNetAddinWizard) Welcome Page
Click ‘Next’ to continue.
Provide the addin name, choose the AutoCAD version and flavor, check whether to start AutoCAD product when debugging, change the API library path if necessary, specify a drawing to open during debugging, and opt whether to use the AutoCAD COM interfaces through the .NET COM interop:
AutoCAD .NET Addin Wizard (AcadNetAddinWizard) Project Page
Click ‘Next’ to continue and set options for the AutoCAD application extension:
AutoCAD .NET Addin Wizard (AcadNetAddinWizard) Application Page
Click ‘Next’ again to continue to set options for the command method class, group, method and flags:
AutoCAD .NET Addin Wizard (AcadNetAddinWizard) Command Page
Click ‘Next’ again to continue and review the summary of the wizard options:
AutoCAD .NET Addin Wizard (AcadNetAddinWizard) Summary Page
After the ‘Finish’ button is pressed, an AutoCAD C# addin project will be created and the solution browser will look like:
AutoCAD .NET Addin C# Project Solution Explorer
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 AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document;
using AcadWindows = 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 AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document;
using AcadWindows = Autodesk.AutoCAD.Windows;
#endregion
namespace AcadNetAddinCS1
{
public class CmdGroup1
{
[CommandMethod("CmdGroup1", "Command1", null, CommandFlags.Modal, null, "AcadNetAddinProject", "Command1")]
public void Command1_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = AcadApplication.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());
}
}
}
}
The leading edge AcadNetAddinWizard can help create various AutoCAD .NET Addin projects (C#, VB.NET and C++/CLI) in Visual Studio 2008 and 2010 both full-fledged and Express.
Recent Comments