External commands start other programs or utilities while AutoCAD or AutoCAD-based product is running.
While AutoCAD or AutoCAD-based product is running, you can invoke other programs or utilities, such as the following:
You can add command definitions by editing acad.pgp in an ASCII text editor. The first section of acad.pgp defines external commands. In addition to command aliases in acad.pgp, you will also find comment lines which are preceded by a semicolon (;) and allow you to add textual information about the file or a command alias.
When you define an external command, you specify a command name to be used at the operating-system 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/shell request],bit flag[,[*]prompt[,return_code]]
The command that is entered at the operating-system prompt. If the name is an internal AutoCAD command name, it is ignored. The name is not case-sensitive.
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 command line switches or parameters. The case-sensitivity of this string depends on the application you want to execute.
A required bit-coded 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 Do not 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 the program 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.
An optional field. It specifies the prompt to display at the program's Command prompt. 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.
An optional bit-coded 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 or AutoCAD-based product 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. The program 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 the program 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 start and cmd operating system commands are very useful when defining external commands. If you specify an executable string that does not use the start or cmd command, the program 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 for the operating system. The start command has many command line switches that affect the display of the new window. To launch a stand-alone application, use start without any command line 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 for the operating system that acts as a shell of AutoCAD or AutoCAD-based product. This window must be closed before control returns to the operating system prompt. Two command line switches, /c and /k, are useful for external commands. The /c command line switch carries out the specified command and then stops (the window closes). The /k command line switch carries out the specified command and then continues (the window remains open). When using the /k command line switch, you must close the command window (with the exit command).
In general, use start to create a new window or launch an application that is to be a separate process from the program. 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 the program. For more information about these commands and switches, see your operating system command documentation.
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 command line switch opens a command window, runs the batch file, and then closes.
The LISTSET command displays the current environment variable settings for the operating system. Because this example uses cmd /k rather than start, the command window must be closed before returning to the program. If you want this window to remain active, use start /realtime. For more information about these commands and switches, see your operating 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. The program 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 operating-system 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