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. In this post, let us see how the AutoCAD .NET Addin Wizard (AcadNetAddinWizard) can help us create AutoCAD .NET addin projects in Managed C++ or the new terminology CLI.
When creating or adding a new Visual C++ project in Visual Studio 2008, choose the AutoCAD .NET Addin template from the Visual C++ node, 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 VB.NET addin project will be created and the solution browser will look like:
AutoCAD .NET Addin C++/CLI Project Solution Explorer
Here is the application extension class created automatically by the wizard into the project:
#include "StdAfx.h"
#include "Namespaces.h"
namespace AcadNetCppAddin1
{
public ref class ExtApp : IExtensionApplication
{
public:
virtual void Initialize(void)
{
//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.
}
virtual void Terminate(void)
{
//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.
}
};
}
Here is the command method class created automatically by the wizard into the project:
#include "StdAfx.h"
#include "Namespaces.h"
namespace AcadNetCppAddin1
{
public ref class CmdGroup1
{
public:
[CommandMethod("CmdGroup1", "Command1", nullptr, CommandFlags::Modal, nullptr, "AcadNetCppAddin1", "Command1")]
void Command1_Method()
{
Database^ db = HostApplicationServices::WorkingDatabase;
Editor^ ed = AcadAppSrv::Application::DocumentManager->MdiActiveDocument->Editor;
try
{
{
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());
}
}
};
}
Regarding the CLI AutoCAD .NET project, the nice header file Namespaces.h may also be good to have:
#pragma once
using namespace Autodesk::AutoCAD::ApplicationServices;
using namespace Autodesk::AutoCAD::DatabaseServices;
using namespace Autodesk::AutoCAD::Runtime;
using namespace Autodesk::AutoCAD::EditorInput;
using namespace Autodesk::AutoCAD::Geometry;
using namespace Autodesk::AutoCAD::Windows;
namespace AcadNS = Autodesk::AutoCAD;
namespace AcadAppSrv = Autodesk::AutoCAD::ApplicationServices;
namespace AcadDocSrv = Autodesk::AutoCAD::ApplicationServices;
The leading edge AcadNetAddinWizard can help create various AutoCAD .NET Addin projects (C#, VB.NET and C++/CLI) in various Visual Studio editions, full fledged or Expresss, 2008 or 2010.
Recent Comments