AutoCAD Scripts & Plots (The Sequel)
A long, long time ago (actually only 40 years ago) in a galaxy far, far away (oops again not that far since it’s our own galaxy) a little company called Autodesk would release a new force bringing shockwaves to the dark and freezing mainframe computer world. I know I’m being dramatic here and I can only carry the analogy so far. Autodesk released AutoCAD version 1.0 back in 1982 as the first Computer Aided Design (CAD) program that would run on a personal computer (PC). You no longer need to be in a room full of computer equipment kept in freezing temperatures to do CAD. In less than a year by version 1.4 AutoCAD added a powerful command called SCRIPT. In my last article, I had focused on AutoCAD’s PLOT command. In this sequel, I will first focus on Scripts and conclude with how Scripts & Plots can join forces for the greater good.
AT THE PREMIER
In the summer of 1988, my first job right out of college was working at TAG Architecture - a small firm located in Burbank, California. While many LA firms in the area at the time were still producing drawings by hand, TAG Architecture produced everything on the computer. From floor plans to elevations and even down to construction details, the entire documentation set was completely drawn on CAD. Drafting boards were a rare commodity at this office because everyone had a desktop computer. The principal of the firm Robb Axton, who had started his own practice for a number of years already, had exceptional and superior AutoCAD skills. I’ve got to say that I’m grateful for all the AutoCAD knowledge I had learned from him at this early stage of my career when many other Architectural firms were slow to jump onto the CAD bandwagon.
Though it was Axton who first introduced me to AutoCAD Script files, the learning of Scripts actually began as a different problem Axton wanted me to solve. The source of that problem was Microsoft. Similar to today Microsoft back then also reigned supreme as the PC operating system (OS) of choice. The OS Microsoft provided was called Disk Operating System (DOS). Unlike today’s Windows OS, the major drawback of DOS was that there was no graphic user interface (GUI). When the computer booted up all you see is the infamous C: prompt. There was no Windows Explorer that is now so conveniently accompanied with the Windows OS. This caused many offices to purchase a third-party application that would provide some kind of GUI to help access and manipulate files stored on the hard drive. One of the popular GUI file management solutions was Bourbaki’s 1DIR (pronounced Wonder) (see Figure 1).
1Dir provided a list of up to two folder file structures side by side for you to view and modify files. Everything on 1Dir is keyboard driven. This included the use of the Up, Down, Left and Right arrow keys as well as all eight Function keys (now we have twelve) on the keyboard. But the real power of this GUI was with the customizable row of boxes at the bottom. Each of these boxes can be modified to launch a unique program opening the file currently selected on the folder file structure window.
Axton then presented me with the problem. Any attempts to launch AutoCAD from one of these customized 1Dir boxes would fail due to lack of sufficient memory. Due to DOS’s infamous memory barrier, programs can only access up to 640k of memory. With 1Dir running as a GUI in the background already there was not enough memory available to launch AutoCAD.
THE COMMAND LINE
I decided to spend the time diving into Microsoft’s and 1Dir’s manuals to find the solution. First, I learned that 1Dir has a command line switch to instruct it to exit. Second and most importantly, I learned that when a DOS batch file ends, memory would be released. So, the solution was to create a batch file that tells 1Dir to exit, and then go to a second batch file to start the AutoCAD program. When the first batch file closed 1Dir’s hold on the memory would be released allowing AutoCAD to use the memory required to launch successfully from the second batch file. Then when AutoCAD exits a third batch file would run (again releasing AutoCAD’s hold on the memory) to relaunch the 1Dir file management GUI. This solution worked perfectly. But I could not figure out how to instruct AutoCAD to open the drawing file selected in 1Dir. All AutoCAD would do is launch, land on the Main Menu startup page and come to a screeching halt (see Figure 2).
Though Axton had told me that using Scripts can solve this problem, I had no idea what Script files are all about. Also searching the AutoCAD manuals on the command SCRIPT only gave me information on how this command is invoked from inside AutoCAD’s graphics drawing window. I could not figure out how a Script file can help at AutoCAD’s Main Menu page. This is when I learned from Axton that like 1Dir AutoCAD has a command line switch or parameter that launches a Script file.
So, putting it all together I first modified one of 1Dir’s customizable boxes to run batch file 1Q.bat that quits 1Dir along with the following commands:
rem the following line exits 1Dir
rem then release memory and run A2.bat with
rem %1 = drawing currently selected
rem %2 = location and name of script file
c:\A2.bat dwg-selected c:\2.scr
Second, the A2.bat file would launch AutoCAD passing these two parameters:
rem launch AutoCAD with parameters for dwg & scr
c:\ACAD\ACAD.exe %1 %2
rem then release memory and run 1D.bat to restart 1Dir
Following ACAD.exe are parameters: %1 and %2. The first parameter (%1) AutoCAD always interprets as a drawing file which in this case is the file selected in the 1Dir folder window (dwg-selected) passed on from the first batch file that exits 1Dir. The second parameter (%2) AutoCAD always interprets as a Script file for it to immediately run when launched (c:\2.scr) again passed on from the first batch file.
From this exercise, I learned that a Script file is basically a text file saved with a file extension of .scr that includes commands to tell AutoCAD what to do. Back to the movie analogy, it’s almost like an actor reading the lines from a movie Script. AutoCAD reads the lines in the order listed from the Script and executes each as if someone is actually typing them in from the keyboard.
This is when I learned that commands from a Script file even works on AutoCAD’s Main Menu page. In this case the Script file named 2.scr would instruct AutoCAD at the Main Menu to execute item number 2. Then because the drawing name is already supplied with the %1 parameter AutoCAD would already have this embedded in its memory. Then all that’s left for the Script file to do is instruct AutoCAD to hit “Enter” to complete the drawing opening process.
This is what is contained in Script file 2.scr:
; enter the number 2 on Main Menu page
; include an empty line below to represent Enter
; script file ends
The semicolon “;” in a Script file is interpreted by AutoCAD as a comment like “rem” in a DOS batch file. Also, an empty line is interpreted as an “Enter” sent from the keyboard.
Since transitioning from running on DOS to the Windows OS, AutoCAD has both dropped the Main Menu landing page as well as the two default command line parameters. Now after Acad.exe you must use the /b switch to precede a Script file name. So, you can still launch a Script file immediately after AutoCAD starts without the need to invoke the Script command.
USEFUL FOR PRESENTATIONS
The second method I’ve learned to use Scripts is as a presentation tool within AutoCAD. Instead of Zooming or Panning around in the drawing, you can save the current graphic drawing view as an AutoCAD slide file (.sld) with the MSLIDE command and then use the VSLIDE command to bring up the saved view at a later date for viewing. This allows you the option to plan out your presentation and sequentially bring up the saved slides to show to the client without having to wait for the drawing to REDRAW or at worse REGEN. This is again where a Script file can become a very useful tool. The Script file would include the commands instructing AutoCAD to sequentially bring up each slide, pause for so many seconds by using AutoCAD’s DELAY command and then continue to bring up the next slide for presentation (see Figure 3).
Two additional commands were added to enhance Script automation. As early as 1984 AutoCAD version 2.0 added the RSCRIPT command. Rscript instructs the Script file to repeat from the beginning so a slide presentation can loop and play over and over again. Then by AutoCAD 2016 the very much needed SCRIPTCALL command was added. Scriptcall is like DOS batch file’s Call command. Scriptcall offers you the option to run another Script file from within the current Script file. Then after the commands in that other Script file ends, AutoCAD will return to the original Script file and continue from the point where it left off. I’ll demonstrate in a later section of this article as to how Scriptcall can be used very effectively with plotting.
The first and second methods of Script file use I’ve mentioned can be combined and implemented together very effectively. AutoCAD can be set up to launch with a Script file showing a sequence of slide presentations. This kind of presentation is great for exhibitions so those who walk by can view various images shown one after another within the AutoCAD GUI.
AUTOMATE LAYER CONTROLS
A third method I’ve learned when Script files come in handy is with setting up the drawing’s Layer status. Instead of manually typing entries on the keyboard to turn Layers On and Off or Thaw and Frozen, all these commands can be included in a Script file to be executed without human intervention. Here’s an example of a typical Script file that adjusts Layers in the current drawing:
; Set Expert=1 to suppress additional Layer prompts
; Begin Layer command
; Set Layer to 0, Thaw & Turn On All
_SET 0 _THAW * _ON *
; Turn Off All Layers except those that begin with “A”
; and Off Layer names that match the following:
; Finally Turn Layer 0 back On
; empty line above to finish Layer command
; Run Regen for Thawed Layers
; Set Expert back to 0 matching office standards
; script file ends
POWERFUL FOR PLOTTING
The method I’ve learned is of most useful for Script files is to assist with Plot automation. Though Plot Scripts can reduce man hours on plotting, they may be a bit more challenging to compose. One way to facilitate in building your own custom Plot Scripts is to launch the PLOT command from AutoCAD’s Command line prefixed with a hyphen “-“. This will bypass the Plot GUI and return AutoCAD to the command line plotting glory days. Next, cycle through the prompts and respond with the desired plot options (see Figure 4).
Then, press “F2” on your keyboard to open the AutoCAD Text Window. Finally select the texts, copy and paste the –PLOT command sequence into Notepad. I typically would keep AutoCAD’s prompts by commenting them out with a semicolon “;”. This way I know the reason for the response I’m providing (see Figure 5).
Now, save this file with a .scr file extension and you’ve got your first Plot Script file. Also go to the beginning of this Plot Script and add the Scriptcall command to reference a Script file that turns Layers On and Off. When this Plot Script runs the drawing’s Layers status will be set automatically prior to automating the Plot command sequence. Now you no longer have to open each drawing and manually set Layers before plotting.
PLOTS & SCRIPTS
Since there are a variety of options that can be chosen to generate the desired Plot, I created an app called Plot Script Magician (PSM) to assist with creating Scripts for Plots. I purposely customized PSM with a GUI similar to AutoCAD’s Plot command. This makes it easier for selecting the correct options to properly generate the corresponding Script (see Figure 6).
Also, since AutoCAD is missing the feature to automate plotting of multiple saved Views in the drawing, I’ve added the feature in PSM. A list of saved Views is presented in a GUI for selection. PSM will generate a Script file that will automate the plotting of these selected Views (see Figure 7).
Finally, you’ll need an app similar to Batch Plot I mentioned in my previous article that can associate Scripts to multiple drawings for batch processing. Autodesk used to offer ScriptPro which runs as a separate application alongside AutoCAD. Unfortunately, Autodesk chose to abandon further development starting with the Windows 10 64-bit OS. A free comparable alternative is AutoScript. Unlike ScriptPro, AutoScript installs and runs inside AutoCAD. AutoScript offers you the option to select a Script file, add drawings you want the Script file to run on and save this as a project file for running again at a later date.
Though AutoScript offers extremely nice features, there are drawbacks. In addition to this being a third-party application, it’s an ARX app. There’s no guarantee that with future releases of AutoCAD there will be a newly compiled ARX app that will be available for download. So, I decided to develop my own app using AutoLISP / Visual Lisp called Drawing Script Magician (DSM) (see Figure 9).
DSM just has the basic features I need to perform batch Drawing Script processing. Using the DSM GUI, I choose a Script (SCR) file like the Plot Script generated from PSM, then select all the Drawings (DWG) I want the Script file to run on, save this association List (LST) for processing again later and then click the command (CMD) Start. Though there are no progress bars or flashy windows, DSM will magically open each drawing, execute the commands listed in the Script like Layer settings and Plot, close the drawing, move on to the next drawing until the entire job is completed.
Recently, clients as well as City Review agencies have opted to go with digital file submissions rather than an actual hardcopy plot set. This means the time spent sending the plot files to the plotter and waiting for the sheets to “ooze out” have been eliminated. But AutoCAD still requires time to go from drawing (DWG) to plot (DWF or PDF). I look forward to the day, hopefully in my lifetime, when this can be done instantaneously. That’s when we can all CAD happily ever after.
THE END (for now)...
Mr. Paul Li graduated in 1988 from the University of Southern California with a Bachelor of Architecture degree. He worked in the Architectural field for small to midsize global firms for over 33 years. Throughout his tenure in Architecture, he has mastered the use and customization of AutoCAD. Using AutoLISP/Visual Lisp combined with Dialog Control Language (DCL) programming he has developed a number of Apps that enhance the effectiveness of AutoCAD in his profession. All the Apps actually came out of meeting challenging needs that occurred while he worked in the various offices. He has made all the Apps available for free and can be downloaded from the Autodesk App Store. Though he recently retired from the Architectural profession, Paul continues to write articles depicting his past work experience. Some of these articles can be found in AUGIWorld Magazine where he shares his knowledge learned. Paul can be reached for comments or questions at PaulLi_apa@hotmail.com.