0% found this document useful (0 votes)
13 views13 pages

AutoCAD Tip - How To Write Command Scripts and Automate Plotting - CADnotes

This document provides a detailed guide on how to write command scripts for AutoCAD to automate plotting tasks. It covers defining processes, creating and testing script files, and debugging them, emphasizing the benefits of automation in improving workflow efficiency. Additionally, it highlights the use of scripts for various tasks in AutoCAD and AutoCAD LT, along with tips for effective script writing.

Uploaded by

AMANUALE D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views13 pages

AutoCAD Tip - How To Write Command Scripts and Automate Plotting - CADnotes

This document provides a detailed guide on how to write command scripts for AutoCAD to automate plotting tasks. It covers defining processes, creating and testing script files, and debugging them, emphasizing the benefits of automation in improving workflow efficiency. Additionally, it highlights the use of scripts for various tasks in AutoCAD and AutoCAD LT, along with tips for effective script writing.

Uploaded by

AMANUALE D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

HOME TRAINING BOOKS SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT

BAHASA INDONESIA ADVERTISEMENT

FEATURED AUTOCAD REVIT INVENTOR MICROSTATION

You are here: Home / AutoCAD / Learn how to write command scripts for AutoCAD and automate your
plotting

Learn how to write command scripts for


AutoCAD and automate your plotting
March 14, 2012 by Paul Munford — 64 Comments

In this Article...

1. What is a script?
2. Defining a process
2.1. Recording the steps
3. Creating the script file
3.1. Editing out the Junk
4. Testing the script
4.1. Debugging
5. Adding Comments (putting some junk back in)
6. How could you use AutoCAD Scripting to automate your workflow?
HOME TRAINING BOOKS SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT
One of the great benefits of using AutoCAD to create your technical drawings is the ability to adapt
AutoCAD to suit
BAHASA your company’s processes. If you can establish a technical drawing process that you
INDONESIA ADVERTISEMENT
perform frequently – you can automate it with AutoCAD. If you’ve ever had to do the same thing with
AutoCAD twice – think about how you could automate it so you never have to do it again.

One of the easiest ways to automate a process within AutoCAD is to write a script. In this post, I will
demonstrate how to write and develop a script for AutoCAD. In this example we will write a script that will
automate a typical plot routine.

What is a script?
In computer programming terms, a script is a programme that will run with no interaction from the user. To
AutoCAD, a script file is an ASCII text file that contains a set of command line instructions for AutoCAD to
follow – just like an actor reading from a script. AutoCAD script files always have a file extension of ‘.scr’.

Defining a process
Before we can automate a process, first we have to define it. In this example we will write a script file that
will create an A1 PDF plot of a drawing. We will work through the instructions that we would usually need to
give AutoCAD to make a plot, and make a note of them so that we can write it up into a script.

Recording the steps


AutoCAD script files cannot interact with dialogue boxes, so we need to work out what we would type at the
command line to produce our plot. To this end we will use the command line version of the plot command ‘-
PLOT’ (the hyphen suppresses the plot dialogue) and we will manually step through the options to produce
our plot.

“ Tip: If you don’t know the answer to the question AutoCAD is asking you, type ‘?’ at the
command line and hit return to see a list of available options. Copy these options out into a text
file for later reference. You may have to step through the routine a few times to get all the
answers you need.

When we have produced a plot manually, we can open up the text window (hit F2 on your keyboard) to
review the steps.
HOME TRAINING BOOKS SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT

BAHASA INDONESIA ADVERTISEMENT

Creating the script file


The next step is to open a new blank notepad file (Please don’t be tempted to use Word or another word
processing programme for this!). Copy the commands from the AutoCAD text window, and paste them into
your notepad file.

Editing out the Junk


The next step is to edit out what you don’t need.

You don’t need AutoCAD’s command line prompts. You do need your replies. In the image below I have
highlighted what can be stripped out. An empty line is equivalent to you pressing ‘Return’ on your keyboard,
so leave those empty lines in!

Watch out for character wrapping inherited from the AutoCAD text window. Make sure all the text for each
step is on the same line.
HOME TRAINING BOOKS SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT

BAHASA INDONESIA ADVERTISEMENT

You should end up with something that looks like this:

Don’t forget that you will need an empty line at the end of your script. This is equivalent to pressing ‘Return’
to complete the command.

Testing the script


The next step is to test the script. First, close down the text file and change the file extension to ‘.scr’

“ Tip: make sure that Windows is showing file extensions before you do this!
HOME TRAINING BOOKS SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT

BAHASA INDONESIA
Free PCB CAD
ADVERTISEMENT
Libraries

Ultra Librarian Download

Next, simply drag and drop your Script file into AutoCAD to run it.

Debugging
It may take you a couple of goes to get your script to run. Use the text window to see how far your script ran
before it stalled. Make the corrections in the .scr file and keep trying until you are happy!

Adding Comments (putting some junk back in)


Now you have a running script file it is a good idea to add a few comments to remind you what you did. You
never know, it might be you who has to re-write the script in six months time…

AutoCAD will ignore any line in your script file that is preceded by a semi-colon. My version of the script
ended up looking like this:
HOME TRAINING BOOKS SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT

BAHASA INDONESIA ADVERTISEMENT

How could you use AutoCAD Scripting to automate


your workflow?
AutoCAD scripts can be used to automate many tasks. You could use a script to add your corporate
standard layers or styles to a drawing. You could write a script to update your title block. And of course you
could adapt the script we’ve just finished writing to automate many of your plotting tasks.

AutoCAD scripts also work for AutoCAD LT, and you can run scripts on a whole batch of drawings using a
windows .bat file or by using the free Scriptpro program from Autodesk labs.

Free PCB CAD


Libraries

Ultra Librarian Download

Next time we will look at the differences between scripts and Macros.
Until then – stay lucky.
HOME TRAINING BOOKS SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT

BAHASA INDONESIA ADVERTISEMENT


About Paul Munford
Paul Munford is the CAD/CAM manager at Halstock cabinet makers in the UK.
Paul is a contributor to AUGIworld and D3D Magazine, and has been a speaker at
Autodesk University for the last three years.
Paul is a firm believer that your CAD software shouldn't hinder your creativity or productivity and
writes awesome tips, tricks and tutorials for AutoCAD and Autodesk Inventor on his blog
Cadsetterout.com.
Paul Is currently working on his first eBook '101 AutoCADTips' You can find out more here:
http://cadsetterout.com/coming-soon-101-autocad-tips/

Filed Under: AutoCAD


Tagged With: AutoCAD script, autocad tips

Wholesale Eco-Friendly Verified PCB CAD Download Flutter SDK


Double Sided Large Libraries
Whiteboard Magnetic
Dry Erase Calendar
Ad Alibaba.com Ad Ultra Librarian Ad Flutter
HOME TRAINING BOOKS 5 EMAIL NEWSLETTER
SUBSCRIBE TO OUR ABOUT

Article Rating
BAHASA INDONESIA ADVERTISEMENT

 Subscribe  Login

Join the discussion

{} [+] 

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

64 COMMENTS  

penny
 1 year ago

When I hit F2 is doesn’t show the detail of my plot, i.e. paper size, plot offset, pen settings, etc.

0 Reply

Konstantinas
 1 year ago

Hi Paul Munford,
Maybe you have something to share about following:
“you can run scripts on a whole batch of drawings using a windows .bat file”
maybe some examples?

1 Reply

Scott
 2 years ago

I have been using Scripts since 2005 and am able to remember them better than AutoLISP. As such, I occasionally
have an AutoLISP command pop into my head, and have to figure out how to write it as a script. As such, I have
created 20+ script routines for work and have now had a new concept pop into my head and I would like to figure
out this one too. I like the new commands DIMLAYER and XREFLAYER, and find them to be extremely handy. I am
now working on setting up a INSERTLAYER, but I want to set it up with three different titles so that the company I
HOME
work TRAINING
for can bring in blocksBOOKS SUBSCRIBE
from three different TOIfOUR
areas. I canEMAIL
figure NEWSLETTER
out how to do this, it ABOUT
will save about 15-20
minutes per day, per job (our company did 150+ jobs last year). So far, I have figure out how to open Windows
Explorer to a different drive, I just haven’t figure out how to open a particular folder on that drive.
BAHASA INDONESIA ADVERTISEMENT
0 Reply

Thomas
 3 years ago

Hi Paul,
Thanks a lot for these two posts about scripts and macros. I used to use lisps on an old version of Autocad. Now,
I’m using LT and the lisps are useless. Am i wrong or scripts and macros can only use commands and options
offered at the command line and therefore cannot really replace lisps? Is there a way to apply lisps to LT? Thanks
again for your help. Best.
Thomas

0 Reply

Edwin Prakoso Editor

 Reply to Thomas  3 years ago

Hi Thomas,

You are correct. Scripts and macros are limited to AutoCAD native commands only. AutoCAD LT doesn’t support
customization with AutoLISP, add-ons, and APIs. If you want to use AutoLISP, then you need to use AutoCAD.

0 Reply

Ivan Greco
 5 years ago

At the end of script, how to close the program dwg trueview? Which one command to use? “_Close” not function.
Thanks.

0 Reply

หนังxใหม่
 7 years ago

Hey! Ƭhis is my fіrst commеnt here so I just wanted to give a quick shout out and
tell you I genuinely enjoy reading your ƅlog posts.
Сan you suggеst any otheг blogs/websites/forums that
HOME
deal TRAINING
with the same topics?BOOKS
Many thanks!SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT

-3 Reply
BAHASA INDONESIA ADVERTISEMENT

ANUJ MONDAL
 7 years ago

sir, Ineed to plot some points all at a go , in autocad 15 . The coordinates ( x, y, z) of the points along with elevation
are in csv file. What I need is to plot the points with ID and elevation (z) displayed. I could manage some how to
plot points from csv file but id and z values could not be displayed

0 Reply

Mathew Joy
 7 years ago

Hi guys,
Looking for a script file for cleaning the architects background. It includes changing text style, delete the hatches
and layer colour to cyan. Could some one please give me some suggestions how to write a script for it.
regards
mathew

0 Reply

Paul
 Reply to Mathew Joy  7 years ago

Hi Matthew,

Follow the steps above.

1. Work out how to do it at the command line.


2. Type it into a text file.
3. Test!

Post your results on the AutoCAD Forums if you are having trouble, and remember to post a link here so that we
can come over and help!

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bd-p/130

Paul
1 Reply
HOME TRAINING BOOKS SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT

praveen
BAHASA INDONESIA
 7 years ago ADVERTISEMENT
I Friends, I want one program that satisfy below Conditions.

1. In Rectangle Some lines are there , i will select that rectangle and i will give offset command and some offset
distance

Now i what in that rectangle all the lines have offset lines

0 Reply

Billy Lobb
 Reply to praveen  11 months ago

did u ever figure that out IM having trouble on rectangle and then the offset not reading it on command line

0 Reply

« Previous 1 2 3 4

Search the site ...

Join Our Free Email Newsletter

Email

Name

SUBSCRIBE NOW

FEATURED
HOME TRAINING BOOKS SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT

BAHASA INDONESIA ADVERTISEMENT

10 Revit Hacks to Make Your Revit


View Compelling
These simple hacks can make your Revit views
artistic and compelling. Without having to spend
hours to render the views!

RECENT ARTICLES

Autodesk Forma Design Contest

Revit 2025: Toposolid Enhancements

Free Dynamo Graph: Auto Dimensions from Grids


and Walls
HOME TRAINING BOOKS SUBSCRIBE TO OUR EMAIL NEWSLETTER ABOUT

NEW ON CADNOTES MEET THE AUTHORS


BAHASA INDONESIA ADVERTISEMENT
Autodesk Forma Design Contest

Revit 2025: Toposolid Enhancements

Free Dynamo Graph: Auto Dimensions from Grids and


Walls

How to: Use Dynamo Graph in Dynamo Player

Model-Based Progress Tracking in Autodesk Build

GET CONNECTED

© 2009 – 2024 CADnotes · Feedback · Privacy Policy · Become an affiliate

You might also like