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 Local Commands Creator of AutoCAD .NET Addin Wizard (AcadNetAddinWizard) can help create local command definitions, local command group class, various culture-specific resource files, and localizable strings in the RESX files for AutoCAD .NET addin projects friendly, quickly and automatically.
The Local Commands Creator/Wizard 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 Visual VB.NET Items node of the Installed Templates and its various item wizards including the Local Commands Creator/Wizard appear in turn in the middle pane:
A kind reminder: though the Local Commands wizard appears in the same places as other item templates either provided natively by Visual Studio or additionally by somebody else, it is not a template actually. It is a real-wizard-sense wizard as mentioned earlier. That is why the term ‘wizard’ is always used instead of ‘template’ in our discussions, articles, and tools. The word ‘creator’ may seem just better and we use it alternatively too.
After an item name is given, the following Local Commands Wizard welcome page will show up:
Click ‘Next’ to continue and choose what cultures (languages) you’d like the local commands support:
Click ‘Next’ to continue and set options for the local Command Group:
Click ‘Next’ again to continue to set options including Global Name, Command Flags, Context Menu types and Document/Application Wide for the local commands:
Click ‘Next’ again to continue and review the summary of the wizard options:
After the ‘Finish’ button is pressed, an AutoCAD command group class along with some resource (.RESX) files corresponded to the culture (language) selection in the wizard page will be created and the solution browser will look like:
Here is the command group class and its local commands that are 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 AcadNetAddinVB1
Public Class LocalCommands1
<CommandMethod("LocalCommands1", "Command1", "LocalCommands1_Command1_ID", CommandFlags.Modal, Nothing, "LocalCommands1.chm", "LocalCommands1_Command1_Index")> _
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_MSG_BEGIN
Debug.WriteLine("Command1 ran.")
ed.WriteMessage("Command1 ran." & vbLf)
'DEBUG_MSG_END
tr.Commit()
End Using
Catch ex As System.Exception
Debug.WriteLine(ex.ToString())
ed.WriteMessage(ex.ToString())
End Try
End Sub
<CommandMethod("LocalCommands1", "Command2", "LocalCommands1_Command2_ID", CommandFlags.Transparent Or CommandFlags.NoHistory, Nothing, "LocalCommands1.chm", "LocalCommands1_Command2_Index")> _
Public Shared Sub Command2_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_MSG_BEGIN
Debug.WriteLine("Command2 ran.")
ed.WriteMessage("Command2 ran." & vbLf)
'DEBUG_MSG_END
tr.Commit()
End Using
Catch ex As System.Exception
Debug.WriteLine(ex.ToString())
ed.WriteMessage(ex.ToString())
End Try
End Sub
<CommandMethod("LocalCommands1", "Command3", "LocalCommands1_Command3_ID", CommandFlags.Modal Or CommandFlags.UsePickSet Or CommandFlags.Interruptible, Nothing, "LocalCommands1.chm", "LocalCommands1_Command3_Index")> _
Public Sub Command3_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_MSG_BEGIN
Debug.WriteLine("Command3 ran.")
ed.WriteMessage("Command3 ran." & vbLf)
'DEBUG_MSG_END
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
Here is the string table of one example resource file (in German language) that is created automatically by the wizard into the project:
Then you can translate the command names (the various CommandX here) into the right languages (cultures) by yourself, or collect these resource strings using some tools and assign the localization task to your vendors when necessary and you continue to focus on your core coding work.
A recommended good practice: Well think about your objectives beforehand, e.g. what languages/cultures your application is going to support, how many commands you need, what names they should have, should they be in a single command group or a few, what name the command group(s) is (are), what command flags each command should have, does each command have a context menu or not, is it document wide or application wide, what help file (if any) the commands are supposed to use, etc. Then use the Local Commands Creator to define all these in a single central place and put all relevant code into a single class. Of course, this does not prevent you from creating any extra classes, dialogs/forms and resources for any command methods or making any manual tweaks to the local command and group definitions when necessary.
Give the Local Commands Wizard of the leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) a try and you will not feel any regret.
Thanks for making these great tools available. You are a great service to the world of AutoCAD programmers.
Posted by: A Facebook User | 05/01/2012 at 04:55 AM
You are very welcome.
Posted by: Spiderinnet1 | 05/01/2012 at 05:36 AM