A while back, I received some survey data in the form of a comma-delimited text file containing rows of Northings, Eastings, & elevations. I needed to take that information and place blocks at every location in my drawing. At the time I only had plain AutoCAD (I wasn’t using Civil 3D yet). Being lazy, I wasn’t about to sit there and type the coordinates by hand. So I wrote a script! Here is how I did it.
I opened the text file in Excel and did a Save-As so I wouldn’t ruin the original file. Then I re-arranged the data so it would make sense in a script. Remember, a script will run as if you were typing the commands in the command line.
Here is what I wanted my script to do: insert a specific block at each location (Northing-Easting). Simple enough.
The way the survey data was arranged was Northing first, then Easting, then elevation.
AutoCAD Fact: When you insert a block, AutoCAD wants the X coordinate before the Y coordinate.
Since the Northing is the Y coordinate and the Easting is the X coordinate, I needed to put the Easting column before the Northing column.
In Excel I clicked on the “A” column, right-clicked, and selected “Insert” to insert a blank column in front of the Northings.
Then I rearranged the Northing-Easting data so it was in the correct order with the Eastings before the Northings. To do this I would select an entire column, right-click, and select Cut. Then select another blank column, right-click, and select Paste. Do this until you have the columns arranged with the Eastings before the Northings.
AutoCAD Fact: When the insertion command asks you where to place a block, you have to type coordinates with commas inbetween.
To get the commas in Excel, add columns between the Northing, Easting, & elevation columns and paste commas in them. To do this, type a comma in the first cell, then select the entire column, right-click, and select Paste. This will put commas into each cell of the column.
In cell “1A” I started writing the block insertion macro – a series of commands seperated by spaces. Remember, in AutoCAD a space is the same as hitting Enter on the keyboard.
In this case I typed:
“Epp” is the name of the block that I have in my drawing. Note that I added a space after “epp” (because after the block name is typed you need to hit enter).
Then, just like the commas, copy & paste the macro into the rest of the cells of column A.
AutoCAD Fact: The INSERT command also requires you to specify a scale and rotation angle for each block inserted.
Thus in cells G, H, & I, I typed ~1, ~1, ~0 respectively.
If you want to specify a scale-factor other than 1 for your block, you could change this. For example, if you wanted the blocks to be 20-scale, you would type ~20, ~20, ~0. The same goes for the rotation angle. If you wanted all your blocks to be at a 45-degree angle, instead of typing ~0 in the last column, type ~45.
You may be wondering why I added a ~ in front of each number. Hang on. I’ll show you why later.
Copy all the cells…
Open Microsoft Notepad (or similar text editor) and paste the data into it…
You will notice tabbed spaces exist where the cell divisions were in Excel. To remove those tabs, highlight one of the tabbed spaces, right-click, and select copy.
Then select Edit –> Replace…
In the “Find what” field, right-click and select Paste…
Leave the “Replace with” field as-is and click the “Replace All” button.
Notice the tilde (~) symbols on the right side of the text file? You will need to replace those with spaces. If we hadn’t put tildes in, there would be no way to put spaces between the numbers. To replace the tildes with spaces select Edit –> Replace…
In the “Find what” field, type ~. In the “Replace with” field simply hit the space bar once. Then click the “Replace All” button.
When saving the text file as a script, you need to set the “Save as type” to “All files” (see below) so that it will accept the .scr extension.
The script is now complete! Once you have saved it with a .scr extension, type SCRIPT on the command line in AutoCAD and browse to open your script file. It will run immediately inserting blocks at every coordinate & elevation.
This method is much easier than typing each coordinate by hand and it saves you from making costly mistakes.