Autocad Script Generator

Autocad can be driven with a text script. It has had this capability since its beginning (about 30 years). Its largely forgotten now but its a real power tool that can process dozens or even hundreds of files in a few minutes. I use it for batch printing and modifying small shop sketches. A text file with scr extension is made with the file names interwoven with open and close statements. Autodesk makes its own script generator, available on separate download, Script-Pro. It stops and starts autocad with every file because there is a memory leak and over time with large drawings, opening and closing in the same session will slow down. However, just manage your batch sizes and enjoy the blazing speed. I can run at least 50 small shop sketches with no problem. This old conventional approach is about 10 times faster than scriptpro. Its easier and more flexible.

What the end user needs and does not have direct in the autocad package to script a large batch of drawings is a program to interweave the filenames with his script. Excel can do this. The scripts can be stored in a worksheet, for user to add and tweak his own scripts. The form does not need massive amounts of file selection methods. We can sub that out to windows filedialog. The text file is made with Microsoft Scripting Runtime FileSystemObject, which has to be referenced in Tools References. The end result is a text file with extension scr that the user just drops into a blank new drawing. The excel form pops up an explorer window to make that an easy find. The script text file is put into the same directory as the files. It works and it’s simple. i tried to take out all the bells and whistles and just concentrate on the bare routine which is powerful and easy to use.

This version does have two added features. One is a very useful trick. Normally a script cannot be stopped while the user performs random actions from the interface. ScriptPro cannot do that. However, if your script contains an unknown command, like “pause”, the script will stop, the user can perform whatever cleanup actions he desires, maybe just zooming and examining, then the command “resume” will resume the script. I put the resume command into the pgp file. I give it an easy name to type, i use “ZZ”, then the script does a zoom extents, saves the drawing, closes it, opens the next one and stops for me again. I clean up shop sketches with this made by an automated program.

A hardcoded script is the other feature. A favorite script, such as batch plotting 8 x 10 landscape shop sketches to extents, something specific you do a lot, can be hardcoded into the program and once the files are selected, the script can be run directly from code without the intermediary of a text file. Its not technically a script, but the command list is exactly the same and it can be developed and debugged in the script listing on the worksheet. Its not limited to just one script. I have an example for batch plotting to printer and batch plotting to pdf.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.