image image34 Script files seem to be one of the many forgotten frontiers of AutoCAD.  “Back in the day” I knew of many CAD users who couldn’t go a day without running a script file or two.  These days – not so much.  Even still, the trick of yesterday can still help solve many tedious and mundane tasks today.

So what is an AutoCAD script file?  Quite simply a script file is a batch file for AutoCAD.  Windows batch files carry the BAT extension, whereas an AutoCAD script file carries a SCR extension.  The power of AutoCAD script files is in their simplicity.  Look under the hood, and they are nothing more than an ASCII text file containing an AutoCAD command on each line.

Admittedly as AutoCAD has progressed to a more and more graphical of an interface, it has become tougher to figure out the command line version of some commands.  Generally speaking a good place to start is by typing the command with either a “.”, “-“, or “_”.  From that point pay attention to the command line prompts, and begin building your script file.

Recently I received an e-mail from one of my readers inquiring about an easier way translate some raw data in Excel into AutoCAD linework.  Essentially the user had a couple thousand points, that he needed to draw lines between (and you thought connect the dots was only a game for kids).  So the question remained, how could one make AutoCAD play connect the dots based on Excel data.

My answer – get Excel to make an AutoCAD script.

True, one could create a LISP, VBA, or even a .NET application.  But for something like this, simplicity is favored over the advanced stuff offered in the other methods.

So how did I accomplish this feat?

  1. Take a look at the LINE command in AutoCAD
    I’ll admit, this seems a little elementary, but we need to be sure we know what prompts are included in the AutoCAD LINE command.
    So the LINE command prompts me for first a “start point”, and then the “next point”.  The “next point” prompt will continue until enter is pressed.  Knowing that I can begin structuring my script.
  2. Structuring your script
    Knowing the command sequence of the LINE command, I can now sit down and write the framework of my AutoCAD script.  In this case I chose to do the following:
    LINE #,# #,#
    Notice the spaces between each the command, and each coordinate value.  AutoCAD interprets this as an enter.
  3. Writing your Excel formula
    I structured my Excel table such that my first column was my X value, the second my Y value, and finally my third column the AutoCAD script.
    image image35

    My Excel formula looks like this:
    =”line “&A2&”,”&B2&” “&A3&”,”&B3&” ”
    image image36

  4. Creating the script file
    Once your Excel table is set up properly, simply copy and paste the “Script” column to a new Notepad file, and save it with a SCR extension (rather than a TXT) extension.
  5. 5. Run the Script file
    Running a script file is actually pretty easy.  Simply drag-and-drop the file into the drawing area of AutoCAD.

Scenarios like the one above are often unique.  Since you’re only going to use the solution once, its hard to justify more complex tools like VBA.  On the other hand script files are small, lightweight, and east to create, making them an AWESOME tool for such one-time-only scenarios.  Although Excel is not built to be a script file writer, it sure does do a good job (in my own opinion).