Today’s post is focused on productivity, an aspect that is sometimes left behind due our intense work load…And I believe that small improvements can make a huge difference on our daily work.
Now the idea is to save us some time typing a new command for AutoCAD, that includes, for instance, database, editor and transaction. Sure you can adjust the code.
How make this work? Simple:
- Create a .snippet file using any text editor (Notepad can do the trick).
- Copy & paste the XML content below
- Save at [My Documents]\Visual Studio 2012\Code Snippets\Visual C#\My Code Snippets\ folder, or other version that you have.
- At your Visual Studio code, type AcadCmd and press TAB, the code should appear, press TAB again to move between command name and method name, both marked in yellow.
Like it? You may adjust to other commands or other pieces that you use repeatedly. Here is the .snippet for download.
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2008/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>AutoCAD Command</Title>
<Shortcut>AcadCmd</Shortcut>
<Description>Code snippet for AutoCAD command method with transaction</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>COMMAND_NAME</ID>
<ToolTip>Replace with the command name</ToolTip>
<Default>myCommandName</Default>
</Literal>
<Object>
<ID>METHOD_NAME</ID>
<ToolTip>Replace with the method name</ToolTip>
<Default>myMethodName</Default>
</Object>
</Declarations>
<Code Language="CSharp">
<![CDATA[
[CommandMethod("$COMMAND_NAME$")]
public static void $METHOD_NAME$()
{
Database db = Application.DocumentManager.MdiActiveDocument.Database;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>