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 VB.NET project in Visual Studio 2008, choose the second Visual Basic node and the AutoCAD .NET Addin template, and provide project name and location:
AutoCAD .NET Addin Template of VB.NET 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 VB.NET Project Solution Explorer
Here is the application extension class created automatically by the wizard into the project:
#Region "Namespaces"
Imports System.Text
'Imports System.Linq
Imports System.Xml
Imports System.Reflection
Imports System.ComponentModel
Imports System.Collections
Imports System.Collections.Generic
Imports System.Windows
'Imports System.Windows.Media.Imaging
Imports System.Windows.Forms
Imports System.Drawing
Imports System.IO
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Windows
Imports AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application
Imports AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document
Imports AcadWindows = Autodesk.AutoCAD.Windows
#End Region
Namespace AcadNetAddinVB1
Public Class ExtApp
Implements IExtensionApplication
#Region "IExtensionApplication Members"
Public Sub Initialize() Implements IExtensionApplication.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.
End Sub
Public Sub Terminate() Implements IExtensionApplication.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.
End Sub
#End Region
End Class
End Namespace
Here is the command method class created automatically by the wizard into the project:
#Region "Namespaces"
Imports System.Text
'Imports System.Linq
Imports System.Xml
Imports System.Reflection
Imports System.ComponentModel
Imports System.Collections
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Windows
'Imports System.Windows.Media.Imaging
Imports System.Windows.Forms
Imports System.Drawing
Imports System.IO
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Windows
Imports AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application
Imports AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document
Imports AcadWindows = Autodesk.AutoCAD.Windows
#End Region
Namespace AcadNetAddinVB1
Public Class CmdGroup1
<CommandMethod("CmdGroup1", "Command1", Nothing, CommandFlags.Modal, Nothing, "AcadNetAddinVB1", "Command1")> _
Public Sub Command1_Method()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = AcadApplication.DocumentManager.MdiActiveDocument.Editor
Try
Using tr As Transaction = db.TransactionManager.StartTransaction()
'TODO: add your code below.
Debug.WriteLine("Command1 ran.")
ed.WriteMessage("Command1 ran." & vbLf)
tr.Commit()
End Using
Catch ex As System.Exception
Debug.WriteLine(ex.ToString())
ed.WriteMessage(ex.ToString())
End Try
End Sub
End Class
End Namespace
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