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 VB.NET project in Visual Basic 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"
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 MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application
Imports MgdAcDocument = Autodesk.AutoCAD.ApplicationServices.Document
Imports AcWindowsNS = Autodesk.AutoCAD.Windows
#End Region
Namespace AcadNetAddinByVBE2008
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 MgdAcApplication = Autodesk.AutoCAD.ApplicationServices.Application
Imports MgdAcDocument = Autodesk.AutoCAD.ApplicationServices.Document
Imports AcWindowsNS = Autodesk.AutoCAD.Windows
#End Region
Namespace AcadNetAddinByVBE2008
Public Class CmdGroup1
<CommandMethod("CmdGroup1", "Command1", Nothing, CommandFlags.Modal, Nothing, "AcadNetAddinByVBE2008", "Command1")> _
Public Sub Command1_Method()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim ed As Editor = MgdAcApplication.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
At this moment, the project is not only ready to build, but also ready to DEBUG. Please just press the F5 key and see what will happen.
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