Run Scripts at Startup (Concept)

AutoCAD

 
Run Scripts at Startup
Concept Procedure Quick Reference
 
 
 

A script that runs at startup can open a drawing and change its settings.

Suppose that every time you begin a new drawing, you turn on the grid, set the global linetype scale to 3.0, and set layer 0 as your current layer, with red as the color. You can do this using a drawing template, but you could do it instead with the following script and store it in a text file called setup.scr.

grid on 
ltscale 3.0 
layer set 0 color red 0 

The first line turns on the grid. The second line sets the global scale for linetypes. The third line sets the current layer to layer 0 and sets its default color to red. AutoCAD assumes that in a script you want to use the version of LAYER command that displays command prompts rather than the dialog box version. The result is equivalent to entering -layer at the command prompt. The fourth line is blank, ending LAYER.

NoteVBA and AutoLISP® scripts that run at startup should check for whether the AutoCAD process is visible or invisible. If the process is invisible, the script should not execute, because the process may be performing background plotting or publishing operations. To check for whether the AutoCAD process is visible or invisible, you can use the Visible property of the Application object in the AutoCAD Object Model.

You could run a script at startup to open a drawing by using the following syntax in the Run dialog box:

ACAD drawing_name /b setup

All file names that contain embedded spaces must be enclosed in double quotes, for example, “guest house”. You can also specify the view that is displayed when the drawing opens by using the /v switch and the view name. The /b switch and the script file must be the last parameter listed.

Including the file extensions .exe, .dwg, .dwt, and .scr is optional. If AutoCAD cannot find the script file, AutoCAD reports that it cannot open the file.

To run the same script at startup but create a new drawing using the MyTemplate.dwt file as the template, enter the following in the Run dialog box:

ACAD /t MyTemplate /b setup

This command creates a new drawing and issues a sequence of setup commands from the setup.scr file. When the script has finished running, the command prompt is displayed. If you want to use the default template for the new drawing, you can omit the /t switch and the template file name.

NoteYou can no longer use this method to start a new drawing and give it a name. Name the drawing when you save it.