Redefining AutoCAD Commands
 
 
 

Using AutoLISP, external commands, and the alias feature, you can define your own AutoCAD commands. You can use the UNDEFINE command to redefine a built-in AutoCAD command with a user-defined command of the same name. To restore the built-in definition of a command, use the REDEFINE command. The UNDEFINE command is in effect for the current editing session only.

You can always activate an undefined command by specifying its true name, which is the command name prefixed by a period. For example, if you undefine QUIT, you can still access the command by entering .quit at the AutoCAD Command prompt. This is also the syntax that should be used within the AutoLISP command function.

Consider the following example. Whenever you use the LINE command, you want AutoCAD to remind you about using the PLINE command. You can define the AutoLISP function C:LINE to substitute for the normalLINEcommand as follows:

_$ (defun C:LINE ( )
(_> (princ "Shouldn't
you be using PLINE?\n")
(_> (command ".LINE")
(princ) )
C:LINE 

In this example, the function C:LINE is designed to issue its message and then to execute the normal LINE command (using its true name, .LINE). Before AutoCAD will use your new definition for the LINE command, you must undefine the built-in LINE command. Enter the following to undefine the built-in LINE command:

_$ (command "undefine"
"line")

Now, if you enter line at the AutoCAD Command prompt, AutoCAD uses the C:LINE AutoLISP function:

Command: line

Shouldn't you be using PLINE?

.LINE Specify first point: Specify first point:

The previous code example assumes the CMDECHO system variable is set to 1 (On). If CMDECHO is set to 0 (Off), AutoCAD does not echo prompts during a command function call. The following code uses the CMDECHO system variable to prevent the LINE command prompt from repeating:

_$ (defun C:LINE ( /
cmdsave )
(_> (setq cmdsave (getvar
"cmdecho"))
(_> (setvar "cmdecho"
0)
(_> (princ "Shouldn't
you be using PLINE?\n")
(_> (command ".LINE")
(_> (setvar "cmdecho"
cmdsave)
(_> (princ) )
C:LINE

Now if you enter line at the AutoCAD Command prompt, the following text is displayed:

Shouldn't you be using PLINE?

Specify first point:

You can use this feature in a drawing management system, for example. You can redefine the NEW, OPEN, and QUIT commands to write billing information to a log file before you terminate the editing session.

It is recommended that you protect your menus, scripts, and AutoLISP programs by using the period-prefixed forms of all commands. This ensures that your applications use the built-in command definitions rather than a redefined command.

See the Overview of File Organization topic in the AutoCAD Customization Guide for a description of the steps AutoCAD takes to evaluate command names.