Inserting List of Points into AutoCAD
Have you ever received a list of coordinates in a CSV file and wanted to place those in AutoCAD? Were you aware this can take as little as 2 minutes?
For a very long time, AutoCAD has supported SCRIPT files. A script file is nothing more than a text file (using only Notepad) that lists the everything that you’d typically type to AutoCAD’s command line.
Take for example the following CSV file. How would we get this into AutoCAD?
To figure out what we need to type in AutoCAD, let’s first start by making sure our Point style is something other than a single dot so it’s more easily visible on your screen. To do this, type “PTYPE” at AutoCAD’s command line. If you don’t get the following dialog, Escape out of the command and type “DDPTYPE” and try again. Select a point style that suites you.
Now that you have a point style that’s more visible on the screen, lets type the Point command and see what input it takes.
You can see from the below image of the command line that once we type “POINT” and press ENTER or SPACEBAR, there’s a little text that displays the current point style and size. You’re then prompted for the coordinates. The points in this example were entered by typing X,Y,Z coordinates for one point and X,Y coordinates for the other. After typing the coordinates and pressing ENTER, the command completes.
To test this theory, we can use Notepad to manually create a Script file. Type the contents you in the below image and name your file with an “SCR” File extension. You’ll want to make sure Notepad’s “Save as type” drop down list is set to “All Files (*.*)” or else Notepad will append a TXT to the end of the file.
One other thing to also note is that the cursor is after the last line, just below it. This is because there’s an “Enter” after the last point…this is just like hitting Enter on the keyboard to complete a command in AutoCAD.
After you’ve created your text file, type the “SCRIPT” command at AutoCAD’s command line and select the Script file you just created. When complete, AutoCAD should have added 2 more points to the drawing.
So, now you know how the basis for a script file (same as you’d type manually) and how to create one (using Notepad), the next thing you need to do is convert the CSV file in Excel to a Script file. That’s actually quite simple.
You’ll use Excel’s “CONCATENATE” function which takes several pieces of text and puts them together. In this example, this is the formula we’re using…
The first piece of text is the Point command. Remember, we can use the SPACEBAR after a command and it’s the same as if we’re pressing the ENTER key. That’s why you see the space after the “POINT“. Each piece of typed text is also contained in double quotes.
Each piece of text that is concatenated is separated by a comma. After the command, you start typing the X-Coordinate which is the Easting column in the CSV file. Because we’re not explicitly typing text, we can simply use a cell reference like so…
When typing coordinates in AutoCAD, we separate them with a comma, so we use another comma for Excel’s Concatenate function, then a comma explicitly typed in double quotes.
Finally, we add the Y-Coordinate which is in the Northing column using a cell reference, again, remembering to separate all the pieces of data with a comma and close the Excel function with a closing parenthesis.
When you’re done, copy the formula to the other cells. You can see in the image, that we have a line of text similar to what we typed in Notepad manually the first time. The below image, I’ve used the F2 key to edit the first cell so you can see the formula and the cell references.
Now that you’re text in Excel is in a Script File format, you can guess the next step. Copy/Paste the text into Notepad, Save with a TXT extension on the file name.
The last step is to run the script file in AutoCAD using the Script command. Zoom Extents in AutoCAD to see your points. The CVS file, Excel File and Script files can be downloaded for examination from this link.
Here’s a screen recording of making and running the script file. As you can see, it takes a CSV file, gets converted into a Script file and places the points in AutoCAD in less than 2 minutes.
Script files are quite easy. You could easily add more text, and use different commands to do the same thing like Insert an attributed block into the drawing and use the point number as the attribute value. You just need to make sure all your system variables are set to prompt you upon insertion for the attribute value.
The only real downside to Script files is they’re not intelligent. They don’t like extra characters or spaces, the don’t work well with commands that prompt for user input or display dialog boxes and they don’t perform conditional logic to do different things depending what they find. They will however call AutoLISP routines so when I have more advanced work I want to do in a script file, I just have the Script call and run my Lisp as well.