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. It also includes various project item wizards, coders, and widgets for AutoCAD .NET programming.
In this article, let us see how the OptionsDialog Extensioner of AutoCAD .NET Addin Wizard (AcadNetAddinWizard) can programmatically add a custom tab to the AutoCAD Options dialog through the TabbedDialogExtension class and VB.NET.
The OptionsDialog Extensioner can be found from the Add New Item UI of both Visual C# and VB.NET of Visual Studio both full-fledged and Express in version both 2008 and 2010. Let’s take the VB.NET of Visual Studio 2010 for an example. The AutoCAD Addin category will appear under the Common Items node of the Installed Templates and its various item wizards including the OptionsDialog Extensioner appear in turn in the middle pane:
Here are wizard pages and some sample fill-outs of the OptionsDialog Extensioner:
The auto-generated class and code may look like the following:
Imports System
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.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
Namespace AcadNetAddinVB1
''' <summary>
''' The settings object that is associated with the UserControl.
''' </summary>
Public Class OptionsDialogExtensioner1_Settings
Private mText As String
Public Property Text As String
Get
Return mText
End Get
Set(value As String)
mText = value
End Set
End Property
'TODO: add more setting properties.
End Class
''' <summary>
''' The class that can be used to extend the AutoCAD Options dialog.
''' </summary>
Public Class OptionsDialogExtensioner1
Public Sub Register()
AddHandler MgdAcApplication.DisplayingOptionDialog, AddressOf AcadApplication_DisplayingOptionDialog
End Sub
Public Sub UnRegister()
AddHandler MgdAcApplication.DisplayingOptionDialog, AddressOf AcadApplication_DisplayingOptionDialog
End Sub
' Make the settings object public and static so that the outside world can access to it.
Public Shared TabSettings As OptionsDialogExtensioner1_Settings = New OptionsDialogExtensioner1_Settings
Private mCustomControl As UserControl1
Private mOptDiaExt As TabbedDialogExtension
Private Sub AcadApplication_DisplayingOptionDialog(ByVal sender As Object, ByVal e As TabbedDialogEventArgs)
mCustomControl = New UserControl1
'TODO: e.g. set default values of controls in the mCustomControl.
mOptDiaExt = New TabbedDialogExtension(mCustomControl, AddressOf okCallback, AddressOf cancelCallback, AddressOf helpCallback, AddressOf applyCallback)
e.AddTab("MyOption", mOptDiaExt)
For Each control As Control In mCustomControl.Controls
AddHandler control.Validated, AddressOf control_Validated
Next
End Sub
Private Sub control_Validated(ByVal sender As Object, ByVal e As EventArgs)
TabbedDialogExtension.SetDirty(CType(sender, Control).Parent, True)
End Sub
Private Sub okCallback()
applyCallback()
MessageBox.Show(TabSettings.Text) ' Should be removed in the final code.
End Sub
Private Sub cancelCallback()
'TODO: e.g. do some cleanup.
End Sub
Private Sub helpCallback()
'TODO: e.g. launch a help file and open a specific topic.
End Sub
Private Sub applyCallback()
'TODO: e.g. write the control values to a setting file or some registry keys/values.
TabSettings.Text = mCustomControl.Name ' Just an example
End Sub
End Class
End Namespace
Next is to launch AutoCAD, NetLoad the assembly, and launch the Options dialog to have a look at the custom tab (TabbedDialogExtension). In case the project itself is also created by the AutoCAD .NET Addin Wizard (AcadNetAddinWizard) and so does the test command, a single F5 press will get us all the way there.
Here is a sample custom tab of the Options dialog beging extended by the TabbedDialogExtension. The real look depends on what the Custom Control is designed.
Give the OptionsDialog Extensioner of the leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) a try and you will not feel any regret.
Recent Comments