Creating Script Files with Excel

image 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

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

  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).

  • Pingback: game hack

  • http://www.facebook.com/amar.gandhi.351 Amar Gandhi

    Hi,
    I am using Eplan P8. I want to write script in EXCEL to make Revision cloud like AutoCAD
    How I can write the script please advise

  • Jasuja

    This is very helpful and save time. Is there any program which can do reverse? ie.from autocad figures to be converted to x,y,z and exported to excel.

  • bodjie

    Hi everyone,
    I want to know if there is a possibility of using script to link excel with autocad,previously i made a database which will be my basis for my drawing,somehow it took time for me to make two activity after one another.please give me a sample or attachment with my post..thank you so much

  • Pingback: RealTime - Questions: "What software would I need to read and process from a couple of files a .txt file and an Excel file?"