Command macro does not work the same as it did in AutoCAD 2008 and previous versions

Mar 4, 2009


Issue:

You want to know how to get a command macro that was created for AutoCAD® 2008 or a previous version to work the same in AutoCAD 2009.

Solution:

Solution

Starting with AutoCAD 2009, command versioning was introduced with the Action Recorder. Command versioning allows AutoCAD to track which command iteration should be used when executing an action macro, script file, or command macro. As a result of this change, some commands might require the use of the ^R control sequence in the command macro.

The ^R control sequence forces AutoCAD to use the newest version of the command. When the ^R control sequence is not used, the oldest version of the command is used. For example, in AutoCAD 2009, the following command macro ends after setting the radius value, which is not what would happen in AutoCAD 2008. The following command macro shows the FILLET command using the Multiple option and setting a radius of 0.1:

^C^C_fillet;u;r;0.1; 

This command macro does not work correctly in AutoCAD 2009, as the FILLET command is being interpreted to use its legacy command behavior, prompting sequence, and options. The following shows the command prompt for the legacy FILLET command: 

Current settings: Mode = TRIM, Radius = 0.1000
Select first object or [uNdo/Polyline/Radius/Trim/mUltiple]: 

To use the newest command behavior, add the ^R control sequence before the command in the command macro. The following shows the same command macro using the new ^R control sequence: 

^C^C^R_fillet;u; r;0.1; 

The command prompt and options for the above command macro look like the following:

Current settings: Mode = TRIM, Radius = 0.1000
Select first object or [uNdo/Polyline/Radius/Trim/mUltiple]:

Running the command macro with the ^R control sequence and the FILLET command makes it behave just like it did in AutoCAD 2008. 

Note: Not all command macros require the use of the ^R control sequence. It is strongly recommended that you only use the ^R control sequence when creating command macros that specify options and input as part of the command sequence. For example, using ^R with the command macro “^C^C^R_fillet” yields the same results as “^C^C_fillet” since no command options or input are specified as part of the command macro.  

The following is a list of some of the commonly used commands with command macros that are affected by command versioning:

  • CHAMFER
  • FILLET
  • LAYOUT
  • LENGTHEN
  • TRIM
  • COLOR
  • EXPLODE

If you are using AutoLISP, you can control which version of a command is used by preceding the Command function with the InitCommandVersion function.  The syntax for the InitCommandVersion function is as follows: 

(InitCommandVersion <version_number>) 

where <version_number> controls which version of the command should be used for the preceding command being executed by the Command function.

The following example demonstrates how to use version 1 (or the oldest version) of the FILLET command:

(InitCommandVersion 1)
(command “fillet”) 

The following prompts are displayed when using version 1 of the FILLET command:

Current settings: Mode = TRIM, Radius = 0.1000
Select first object or [uNdo/Polyline/Radius/Trim/mUltiple]: 

Version 2 of the FILLET command is the second (or, currently, the newest) version of the command, and is equivalent to using the ^R control sequence in a command macro.

The following prompts are displayed when using the second version of the FILLET command: 

Current settings: Mode = TRIM, Radius = 0.1000
Select first object or [Undo/Polyline/Radius/Trim/Multiple]:

Products:

AutoCAD;AutoCAD LT

Versions:

2009

Discuss