Define External Commands (Concept)

AutoCAD

 
Define External Commands
Concept Procedure Quick Reference
 
 
 

External commands start other programs or utilities while AutoCAD is running.

While AutoCAD is running, you can invoke other programs or utilities, such as the following:

  • Windows system commands and utilities, such as start, type, dir, or copy
  • Applications such as text editors or word processors
  • Database managers, spreadsheets, and communications programs
  • User-supplied programs, such as batch files or VBA macros

When you enter an external command, AutoCAD looks for the command in acad.pgp. The first section of acad.pgp defines external commands. You can add command definitions by editing acad.pgp in an ASCII text editor (such as Notepad). To open the PGP file, click Tools Customize Edit Program Parameters (acad.pgp)Click Tools menu Customize Edit Program Parameters (acad.pgp).

NoteBefore you edit acad.pgp, create a backup file so that you can restore it later, if necessary.

When you define an external command, you specify a command name to be used at the command prompt and an executable command string that is passed to the operating system. Each line in the external commands section has five comma-delimited fields, as follows:

command,[executable],flags[,[*]prompt[,return_code]] 
command

The command that is entered at the command prompt. If the name is an internal AutoCAD command name, it is ignored. The name is not case-sensitive.

executable

The constant string sent to the operating system when you enter a command name. It can be any command that you can execute at the operating-system prompt. The string can include switches or parameters. The case-sensitivity of this string depends on the application you are running.

flags

A required bitcoded parameter. Add these integer values in any combination to achieve the result you want.

0 Start the application and wait for it to finish.

1 Don't wait for the application to finish.

2 Run the application in Minimized mode.

4 Run the application “hidden.”

8 Put the argument string in quotes.

Bit values 2 and 4 are mutually exclusive; if both are specified only the 2 bit is used. Using value 2 or 4 without value 1 should be avoided, because AutoCAD becomes unavailable until the application has completed.

Bit value 8 allows commands like del to work properly with file names that have embedded spaces. This eliminates the possibility of passing a space-delimited list of file names to these commands. If you prefer multiple file support, do not use the bit value 8.

prompt

An optional field. It specifies the prompt to display on the AutoCAD command line or for the dynamic input tooltip. The response to this prompt is appended to the string supplied in the executable field. If the first character of the prompt field is an asterisk (*), the response can contain spaces and the user must press ENTER to terminate it. Otherwise, the response is terminated by either SPACEBAR or ENTER. If no prompt is specified, no input is requested; however, you must add a comma if a return code is to be supplied or if you want the prompt to have a trailing space.

return_code

An optional bitcoded parameter. You can add these integer values together in any combination to achieve the result you want. For example, if values 1 and 2 are required, you use 3 as the return code. The values are defined as follows (codes 0 and 4 are meaningless in a windowed environment and are therefore not included):

1 Loads a DXB file. AutoCAD loads the DXB file named $cmd.dxb into the drawing after the command is terminated. After the DXB file is loaded, the $cmd.dxb file is deleted. This action produces the same result as the DXBIN command.

2 Constructs a block definition from a DXB file. AutoCAD creates a block definition from the DXB file named $cmd.dxb. The response to the prompt field is used as the block name. This name must be a valid block name that does not currently exist in the drawing; therefore, this mode cannot redefine a previously defined block. After AutoCAD loads the DXB file, the $cmd.dxb file is deleted. The default name for the INSERT command is set to the newly defined block.

The file can also contain comment lines preceded by a semicolon (;).

Windows System Commands

The start and cmd Windows system commands are very useful when defining external commands. If you specify an executable string that does not use the start or cmd command, AutoCAD is unavailable until that window is closed.

The start command starts a separate window and runs a specified program or command. If start is used without any parameters, it opens a new command prompt window. The start command has many command line switches that affect the display of the new window. To launch a Windows application, use start without any switches. The start command is also very useful for starting a document that is associated with an application. For example, you can use start to directly open a document created with a word processor or an HTML file.

The cmd command opens a command prompt window that acts as a shell of AutoCAD. This window must be closed before control returns to the AutoCAD command prompt. Two command line switches, /c and /k, are useful for external commands. The /c switch carries out the specified command and then stops (the window closes). The /k switch carries out the specified command and then continues (the window remains open). When using the /k switch, you must close the command window (with the exit command).

In general, use start to start a new window or application that is to be a separate process from AutoCAD. Use cmd to run a batch file or command script that does not create a separate window, or to create a window that must be closed before control is passed back to AutoCAD. For more information about these commands and switches, see your Windows system command documentation.

Custom-Defined Commands

The following example defines three new commands: RUN, LISTSET, and DXB2BLK.

RUN, cmd /c,0,*Batch file to run: ,
LISTSET,cmd /k SET,0
DXB2BLK,cmd /c DXBCOPY,0,DXB file: ,2

The RUN command runs a batch file or command script. The cmd command followed by the /c switch opens a command window, runs the batch file, and then closes.

The LISTSET command displays the current DOS environment variable settings. Because this example uses cmd /k rather than start, the command window must be closed before returning to AutoCAD. If you want this window to remain active, use start /realtime. For more information about these commands and switches, see your Windows system command documentation.

The DXB2BLK command creates a block definition from the specified DXB file. The DXB file converts all objects into lines. One beneficial by-product of this procedure is that it provides a simple method for exploding text objects into lines.

DXB2BLK passes the specified DXB file name to the dxbcopy batch file, which copies that file name to the file name $cmd.dxb. AutoCAD then creates a block from the specified DXB file. The name provided to the DXB file prompt is used as the new block name. To create the dxbcopy.cmd file, enter the following at the Windows Command Prompt:

echo copy %1.dxb $cmd.dxb > dxbcopy.cmd 

This creates the dxbcopy.cmd file in the current directory. Move this file to a directory that is in your DOS path, or explicitly specify the file's location in the acad.pgp file. For example, if the dxbcopy.cmd file is in D:\cad, enter the following in the external commands section of your acad.pgp file.

DXB2BLK, cmd /c D:\CAD\DXBCOPY,0,DXB file: ,2

To create a DXB file, choose AutoCAD DXB File Format as the current printer, and then plot to a file. For more information about configuring printers, see Set Up Plotters and Printers in the Driver & Peripheral Guide.