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 C# of Visual Studio 2010 for an example. The AutoCAD Addin category will appear under the Visual C# 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
using System;
using System.Text;
//using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
//using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Windows;
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document;
using AcadWindows = Autodesk.AutoCAD.Windows;
#endregion
namespace AcadNetAddinCS1
{
public class LocalCommands1
{
[CommandMethod("LocalCommands1", "Command1", "LocalCommands1_Command1_ID", CommandFlags.Modal, null, "LocalCommands1.chm", "LocalCommands1_Command1_Index")]
public void Command1_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (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());
}
}
[CommandMethod("LocalCommands1", "Command2", "LocalCommands1_Command2_ID", CommandFlags.Transparent | CommandFlags.NoHistory, null, "LocalCommands1.chm", "LocalCommands1_Command2_Index")]
public static void Command2_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//TODO: add your code below.
Debug.WriteLine("Command2 ran.");
ed.WriteMessage("Command2 ran.\n");
tr.Commit();
}
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
[CommandMethod("LocalCommands1", "Command3", "LocalCommands1_Command3_ID", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Interruptible, null, "LocalCommands1.chm", "LocalCommands1_Command3_Index")]
public void Command3_Method()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = AcadApplication.DocumentManager.MdiActiveDocument.Editor;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//TODO: add your code below.
Debug.WriteLine("Command3 ran.");
ed.WriteMessage("Command3 ran.\n");
tr.Commit();
}
}
catch (System.Exception ex)
{
Debug.WriteLine(ex.ToString());
ed.WriteMessage(ex.ToString());
}
}
}
}
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.
404 on the download link, FYI
Posted by: CAD bloke | 02/24/2012 at 04:19 PM
It seems the Google Doc Share link was broken because of recent build replacement. Got it fixed by redirecting the link to the latest build. The good link can be found in recent posts too.
Posted by: Spiderinnet1 | 02/24/2012 at 06:11 PM