View Full Version : Import Coords from a CSV file ???
robdg
2011-04-29, 05:11 PM
Hey Everyone!
Does anybody know of an easy way to import a bunch of X & Y coordinates into autocad if I have them all typed up in a text file or an Excel CSV file?
It would be nice to just be able to put a little nod or circle at coord. and maybe some text next to it.
Thanks for the help!
Rob
cadtag
2011-04-29, 05:43 PM
easiest thing to do quickly would be to set it up as a script file. Just paste the pertinent text commands in front of the comma-delimited x-y-z coords. so if you want a point object, just add:
POINT<space> in front of every x,y,z,
and save as yourfilename.scr and use the script command to load it.
sandeep_koodal
2011-04-29, 06:15 PM
Hey Everyone!
Does anybody know of an easy way to import a bunch of X & Y coordinates into autocad if I have them all typed up in a text file or an Excel CSV file?
It would be nice to just be able to put a little nod or circle at coord. and maybe some text next to it.
Thanks for the help!
Rob
Please see attachment
robdg
2011-04-29, 06:49 PM
easiest thing to do quickly would be to set it up as a script file. Just paste the pertinent text commands in front of the comma-delimited x-y-z coords. so if you want a point object, just add:
POINT<space> in front of every x,y,z,
and save as yourfilename.scr and use the script command to load it.
Oh yeah, I didn't even think about using a script!.. I could tell it to draw a circle then put piece text next to etc...
Thanks for the suggestion!
robdg
2011-04-29, 08:21 PM
This script is acting really wierd.
I have 358 coordinates. Just X & Y The script should insert a block named "city". It's just a hatched circle.
My format is this:
-insert city 614,45 1 0
-insert city 578,112 1 0
-insert city 730,452 1 0
I have about 358 lines that with different X,Y coords. All the coords are whole numbers and none of them have decimals. When I run the script, it puts in the blocks every where but several of them aren't on the coords from the script!!!
I can select then all and there are 358 little blocks which is right but why would they just jump to other coords that aren't even on the list?
Jmurphy
2011-04-29, 11:23 PM
I can select then all and there are 358 little blocks which is right but why would they just jump to other coords that aren't even on the list?
Make sure you trun off the running osnaps before you run it.
osmose 0
arshiel88
2011-05-02, 10:36 AM
...
My format is this:
-insert city 614,45 1 0
-insert city 578,112 1 0
-insert city 730,452 1 0
...
I think you forgot the Y-scale parameter. Try -insert city 614,45 1 1 0 or just add another space between 1 and 0 in your existing script.
wpeacock
2011-05-09, 05:38 AM
The following is a piece of code for VB that was cobbled together a few years ago from information and help from other augi members on this site.
It required that an excel document (save your csv as an excel) was open at the time and all the x,y coordinates(northing and easting) along with RL's and other info are sucked up and plotted into the drawing.
Note that the text will appear at the same size as what your default is at the time.
It also inserts the block "Station Marker" from C:\Drawings\StationMarker.dwg so you will have to make simular block in that location or rename block and location to suit.
Note:
Column a = station number
Column b = easting
Column c = northing
Column d = rl (set to 0 within code for 2d drawing)
Column e = type of mark (text)
Column f = comments (text)
The code starts to read at the third row (allows for column headers etc.)
I'm not sure if the units in the excel sheet were in metres or mm so you might want to do a couple of dry runs.
Hope you have some fun with this.....
regards
Wayne
Option Explicit
Dim ExcelApp As Object
Dim mspace As AcadModelSpace
Function ExcelConnect()
' This function connects excel with autocad
On Error Resume Next
Set ExcelApp = GetObject(, "Excel.Application")
If Err Then
Err.Clear
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Visible = True
If Err Then
MsgBox Err.Description
Exit Function
End If
End If
End Function
Function ExcelClose()
' This function closes the connection between excel ana Autocad
Set ExcelApp = Nothing
End Function
Function GetCellValue(row As Integer, column As Integer) As Variant
' This function returns the value of a given cell in excel.
GetCellValue = ExcelApp.ActiveSheet.Cells(row, column).Value
End Function
Sub ExcelToAcad()
' declaration of variables
Dim A(2) As Double
Dim B(2) As Double
Dim StationNo As String
Dim EastingNo As Double
Dim NorthingNo As Double
Dim RL As Double
Dim TypeOfMark As String
Dim Comments As String
Dim MtextObj As AcadMText
Dim Corner(0 To 2) As Double
Dim Width As Double
Dim Text As String
Dim StationBlock As AcadBlockReference
Dim StationPts(0 To 2) As Double
Dim PathName As String
Dim i As Integer
PathName = "C:\Drawings\StationMarker.dwg"
ExcelConnect
' giving cell values to points A (from cells C5/D5) and point B (from cells C6/D6)
' The default value for the z coordinate is 0 (drawing in xy plane)
For i = 3 To 250
A(0) = GetCellValue(i, 2) 'Ax
A(1) = GetCellValue(i, 3) ' Ay
StationNo = GetCellValue(i, 1)
EastingNo = GetCellValue(i, 2)
NorthingNo = GetCellValue(i, 3)
RL = GetCellValue(i, 4)
TypeOfMark = GetCellValue(i, 5)
Comments = GetCellValue(i, 6)
Corner(0) = A(0): Corner(1) = A(1) - 1100: Corner(2) = 0
Width = 50000
Text = "STATION No:" & vbTab & vbTab & StationNo & vbLf _
& "EASTING:" & vbTab & vbTab & EastingNo & vbLf _
& "NORTHING:" & vbTab & vbTab & NorthingNo & vbLf _
& "RL:" & vbTab & vbTab & vbTab & RL & vbLf _
& "TYPE OF MARK" & vbTab & TypeOfMark & vbLf _
& "COMMENTS:" & vbTab & vbTab & Comments
StationPts(0) = A(0): StationPts(1) = A(1): StationPts(2) = 0
Set MtextObj = ThisDrawing.ModelSpace.AddMText(Corner, Width, Text)
Set StationBlock = ThisDrawing.ModelSpace.InsertBlock(StationPts, PathName, 1, 1, 1, 0)
Next i
ZoomAll
Set mspace = ThisDrawing.ModelSpace
ThisDrawing.Regen (acActiveViewport)
' Closing the excel-autocad link
ExcelClose
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.