I Command You

Thankfully, I missed the whole DCL dialog coding language days. Don’t get me wrong, DCL is still around but with the addition of VBA into AutoCAD 2000 and then .Net, there is no reason to learn DCL in my opinion. In fact, the need to create a better user interface is what led me to begin looking into VBA from Lisp. I needed some dialog boxes for my lisp routines and VBA was the natural progression.

The more I learned VBA, the more I wanted to code everything in VBA. However, there was one MAJOR downfall. How do you CALL your VBA routines? If you build a lisp function, the routine seems like an actual AutoCAD command. Whereas with VBA, there was no way to type something into the command line (there is always a way but I am talking about cleanly guys) and get to the VBA routine. So for all my VBA routines, I actually had a supporting lisp routine which would create that natural AutoCAD command feel and call the appropriate VBA routine.

Thankfully, .Net is so much cleaner. Way back with our very first programming series, Working with Civil3D 2010 Managed .Net API 101, we looked at creating a command VERY briefly. Let’s walk through this very special tool in a little more depth.

The CommandMethod is an attribute found in the Autodesk.AutoCAD.Runtime namespace so I simply import this in. To make sure that you have Autodesk.AutoCAD.Runtime namespace available and how to import this in, you may want to review the following links:

Working With Civil3D 2010 Managed .Net API 101, Part 1

Working With Civil3D 2010 Managed .Net API 101, Part 2

What the CommandMethod attribute allows you to do is CREATE an AutoCAD native command and assign that command to a routine that you have in your application. However, there are many values that can be passed to this attribute. One of these is values are command flags. Command flags are a bit enum meaning that you can call multiple attributes (use OR) and that they are an enum type. Let’s take a look at some of these.

DocExclusiveLock This flag locks the document . We will talk more about locking the document later.
Modal This flag prevents you from calling the command while another command is active. It is kind of the opposite of Transparent below.
NoBlockEditor This flag prevents your command from being called inside the block editor.
NoHistory This flag will make it so that your command cannot be called simply by pressing enter to repeat last command. It does still show up in the list of priors.
NoPaperSpace This flag prevents your command from being called in paper space.
NoUndoMarker This flag means that if you press undo, your command does not show up and it will undo the command before yours.
Session This flag means that your command will run in application context, not in document context. In other words, you can open another drawing in your drawing and still work in the same command (even though another drawing is current).
Transparent For Civil3D users, we know what transparent means. We can call our command while another command is active.
UsePickSet This flag keeps your current selection active for use with creating a selection set. This is not automatic and still requires you to call GetSelection. However, if there exists an existing selection, it will get called first.

There are more flags but you get the idea. What is more, you can group your commands, you can even add help control to your commands!

Imports Autodesk.AutoCAD.Runtime

Public Class MyCommandClass

    <CommandMethod(“MyNewCommand”, CommandFlags.UsePickSet)> _

    Public Sub cmdMyNewCommandSub()

     ‘Enter your code here

    End Sub

End Class

Once you go .Net, you won’t ever go back to lisp!!

Comments are closed.