• Home
  • Training Books
  • Subscribe to Our Email Newsletter
  • About
    • Contributors
    • Feedback
    • Contact
    • Privacy policy
    • Cookie Policy
  • Bahasa Indonesia

CADnotes

CAD Tutorials and Best Practices for professionals and students

  • Featured
  • AutoCAD
    • AutoLISP
  • Revit
    • Revit Architecture Basic
    • Revit MEP Basic Tutorial
  • Inventor
  • MicroStation
    • MicroStation Basic Tutorial
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...

  • What is a script?
  • Defining a process
    • Recording the steps
  • Creating the script file
    • Editing out the Junk
  • Testing the script
    • Debugging
  • Adding Comments (putting some junk back in)
  • How could you use AutoCAD Scripting to automate your workflow?

One of the great benefits of using AutoCAD to create your technical drawings is the ability to adapt AutoCAD to suit your company’s processes. If you can establish a technical drawing process that you 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.

The plot script in the AutoCAD text window

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.

The unedited plot script in a text file

You should end up with something that looks like this:

The Edited plot script in a text file

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!

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

Dragging a SCR script file into AutoCAD

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:

The finished AutoCAD Plotting script

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.

Next time we will look at the differences between scripts and Macros.

Until then – stay lucky.

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

5 1 vote
Article Rating
Subscribe
Login
Notify of
guest

guest

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

64 Comments
Inline Feedbacks
View all comments
Piyush
Piyush
9 years ago

I wanna separate out different layers…
means i wanna give layer 1 to text and layer 2 to objects using script or lisp…
how can I write programme?

0
Reply
Paul Munford
Paul Munford
Reply to  Piyush
9 years ago

Hi Piyush,

This is a good place to start:
http://www.afralisp.net/index.php

Paul

0
Reply
Piyush
Piyush
Reply to  Paul Munford
9 years ago

Is there any programme ready with you for same thing?

0
Reply
werunga
werunga
9 years ago

how do i open an autocad script file in Autocad 2013?

0
Reply
Paul munford
Paul munford
Reply to  werunga
9 years ago

Hi Werunga,

Exactly as described above!

Paul

0
Reply
Christen
Christen
9 years ago

Importante AutoCAD Civil 3D 2014 dibujos utilizan /autocad
objetivos de corredor de xrefs no se pueden editar en AutoCAD Civil
3D dos mil trece.

0
Reply
Paul Munford
Paul Munford
Reply to  Christen
9 years ago

(Google Translate)

Important Civil 3D drawings using AutoCAD 2014 / AutoCAD
xrefs broker objectives can not be edited in AutoCAD Civil
3D two thousand and thirteen .

0
Reply
Richard Zacher
Richard Zacher
10 years ago

Thank You for the tutorial. I have automated with custom buttons but this method looks more sophisticated.

0
Reply
Paul Munford
Paul Munford
Reply to  Richard Zacher
10 years ago

Thanks Richard. Scripts and button macro’s go great together :D

Keep up the good work.

Paul

0
Reply
Jürgen BEcker
Jürgen BEcker
10 years ago

Hi,

the article is good for a script example. For batch plotting it’s probably better if you use the publish command. Thats much easier.

Regards Jürgen

0
Reply
Paul Munford
Paul Munford
Reply to  Jürgen BEcker
10 years ago

Quite Right Jurgen,

Batch plotting is a powerful function and well worth learning!

Paul

0
Reply
BENITO
BENITO
10 years ago

Paul, I have open many of your autocad videos on youtube and none of them have “AUDIO”
Any particular settings required that we may not know???
Be well
Benito

0
Reply
Paul Munford
Paul Munford
Reply to  BENITO
10 years ago

Hi Benito,

Some of the short recordings I did for Cadsetterout.com many years agin didn’t have Audio (I didn’t know how to do it back then!).

If you direct me to a specific video, I can advise of fix it?

Thanks,

Paul

0
Reply
J-P
J-P
10 years ago

Hello Paul,

I found your website very helpful, and I thought everything was going hunky dory however, I am having a problem loading my script file.

Consider two files …. drawing.dwg and script.scr

when i drag and drop the .scr file onto the AutoCAD canvas, I am getting an error saying can’t find drawing.scr

it is concatenating the drawing name onto the script suffix.

Any suggestions?

Many thanks

0
Reply
Paul Munford
Paul Munford
Reply to  J-P
10 years ago

Hi JP,

That sounds unusual!

Is your script running at all? Do you have any additional spaces at the end of the script that could be causing it to try and run twice?

Paul

0
Reply
Max
Max
10 years ago

Hi,

I have a written a plotting script. Now I would like it to plot all the layouts in a drawing automatically. Is there a way to loop the script, or just make it run through all the layouts?

Thanks!

0
Reply
Paul Munford
Paul Munford
Reply to  Max
10 years ago

Hi Max,

I don’t think that this is possible with a script on it’s own. To do this, you would need to count how many layout tabs you have in the drawing, save this in a variable, and then write a recursive sequence to perform the plot.

It sounds like a job for Lisp to me!

You might be able to do it with ScriptPro:
http://knowledge.autodesk.com/support/autocad/downloads/caas/downloads/content/autodesk-customization-conversion-tools.html

Don’t forget that you can batch plot…

Paul

0
Reply
Zander
Zander
10 years ago

Hmmm… how cool is this scripting.
i did a script for printing.
set my default paperspace to print to my liking, in colour.
But i only seems to get grayscale prints.

Any Idea ?

0
Reply
Paul Munford
Paul Munford
Reply to  Zander
10 years ago

Hi Zander,

Check the bit where it says ‘plot style table name’. If you didn’t put this bit in it might not work. If you put this bit in – make sure you spelled the name of your plot style table correctly!

Paul

0
Reply
SteveH
SteveH
10 years ago

I am trying to write a script in Autocad 2012 to change attributes in a drawing title block, with limited success. see script below;

;————————————————————
;EDIT PROJECT TITLE-E
-ATTEDIT
N
N
A*-TITLE
TITLE1
*
COMPRESSOR GC-201 UPGRADE
TA2015 GC-701 CCC CONTROLLER UPGRADE
;————————————————————
;EDIT PROJECT TITLE-R
-ATTEDIT
N
N
A*-TITLE
TITLE4
*
МОДЕРНИЗАЦИЯ КОМПРЕССОРОВ GC-201
КР2015 GC-701 МОДЕРН-ЦИЯ КОНТРОЛЛЕРА ССС
;————————————————————
QSAVE

;————————————————————
The above works perfectly, BUT…I would now like to modify the script to use a wildcard for the ‘Enter string to change’ line. This wildcard is to enable the change of ANY existing string to the replacement string.

I have tried using *(asterix), but that doesn’t appear to work for full strings, despite the contrary being stated on several websites.

Any advice would be greatly appreciated.

NB. I’m trying to keep this really simple and script based only. So please, no LISP routines.

Cheers,
Steve

0
Reply
Paul
Paul
Reply to  SteveH
10 years ago

Hi Steve,

My understanding is that scripts cannot take values in this way. They are a script – AutoCAD reads the script and executes the commands.

To add inputs, you would need to write a program. For this you would need Lisp, VBA or possibly the action recorder.

I’m happy to be proved wrong if anyone has a better answer!

Cheers,

Paul

0
Reply
« Previous 1 2 3 4 Next »
wpdiscuz   wpDiscuz

Featured

Complete our challenges to work better with AutoCAD!

Learning AutoCAD is not only about knowing all the features. You need to know to to work effectively with it, and they don’t teach it in school or training classes. You can learn with us here!

Recent Articles

  • Autodesk Construction Cloud Activity Log
  • Exporting AutoCAD Plant 3D Model to Navisworks
  • Autodesk Data Connector for Power BI is Now Available

Advertisement

New on CADnotes

  • Autodesk Construction Cloud Activity Log
  • Exporting AutoCAD Plant 3D Model to Navisworks
  • Autodesk Data Connector for Power BI is Now Available
  • Autodesk Forma Design Contest
  • Revit 2025: Toposolid Enhancements

Meet the Authors

avatar for
avatar for
avatar for
avatar for
avatar for
avatar for

Get Connected

CADnotes on FacebookCADnotes on InstagramCADnotes on TwitterCADnotes on YouTube

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

wpDiscuz