15-13a. AutoCAD Export Coordinates Points to CSV

How to Export Coordinates of Points Using LISP to AutoCAD

Since this web tutorial is intended for beginners, here I will describe how to export Coordinates for specific points in the drawing.
Take for example that the drawings have points that are set to specific coordinates (this is quite used in geodesy, but mostly MAP CAD programs and some already have built-in LISP Export programs).

In the picture below, notice that I have created several points on the desktop. Note that with the cursor I have an extra cloud with the coordinate position if I click on the position where the cursor is currently located. (this cloud can be switched on/off at the DYN button (dynamic input)
Coordinates of Points in AutoCAD drawing

How to use LISP?

Load LISP Application in AutoCAD

To use this option (export coordinates to CSV file), a file that has the extension '* .lsp' is used. This so-called scripted code needs to be copied to the "some" folder. Usually this is the AutoCAD folder that contains other files with the LSP extension. In AutoCAD 2007 it is a Express folder (if you installed it when installing AutoCAD)



For this example I found one file (named c2exc2.lsp) that exports coordinates to Excel format. Source code you can see below.

CODE:
;;; Export coordinates of dwg dots in excel format (three decimal places).
;;; Load Lisp (Tools => AutoLisp => Load Application => c2exc2
;;; NOTE: lisp is started by typing c2exc2 commands in the command line

(defun C:c2exc2 (/ coords coor_list elist en fd fname i ss)
(setq ss
(ssget "_:S" '((0 . "*POLYL*,LINE,CIRCLE,ARC,ELLIPSE,SPLINE,POINT"))) i -1)
(repeat (sslength ss)
(setq i (1+ i)
en (ssname ss i)
elist (entget en)
coords (vl-remove-if (function not)
(mapcar (function (lambda (x)(if (eq 10 (car x))(trans (cdr x) 0 1))))
elist)
)
coor_list (cons coords coor_list)))
(setq coor_list (reverse coor_list))
(setq fname (getfiled "Type file name" "" "xls" 1))
(setq fd (open fname "w"))
(foreach coors coor_list
(foreach i coors
(princ (strcat (rtos(car i)) "\t"
(rtos (cadr i))"\t"
(rtos (caddr i)) "\n")
fd)
)
)
(close fd)
(princ)
)


After setting the points on the drawing, it is necessary to load the LISP file that draws the export coordinate of the selected points to the drawing into the CSV file that you can open in Excel.

So to load LISP, click on TOOLS => AutoLISP => Load Application

How to load LISP file?

Load LISP script in AutoCAD

At the next dialog window you find the folder in which you copied the file 'c2wxc2.lsp'. In this case, it is a folder Express and contains the file in question. Select it (tick) and then click the LOAD button. If AutoCAD has successfully loaded the relevant file, this information will be displayed in the field (shown in Figure 4 - 'c2exc2.lsp' successfully loaded)

After uploading the LISP file, you are ready to export specific point coordinates to a CSV file that you can open in Excel. Note the drawing (figure below) for this example of 5 dots (they do not have to look like this, I've shaped them into this layout for easier explanation.) From drawn five points I want to find three point coordinates (ie export them)

In Coomand Line, enter the command "c2exc2" with no quotation marks. Make sure that this command does not always have to be the same file name. That's why you need to keep in mind the name of the command in the source code. See the first row of commands in the source code.

(defun C:c2exc2 (/ coords coor_list elist en fd fname i ss)

So here is the command that LISP launches. (all depends on the developer who programmed the LISP code).

Run LISP file in AutoCAD Command Prompt Line

After pressing the ENTER key, the mouse pointer has been transformed into 'square' and in Command Line AutoCAD requires us to select (highlight) all the points for which we want to export the coordinates. As you select AutoCAD, see link AutoCAD Selection With Mouse.

Selecting Points in AutoCAD

Select multiple points in AutoCAD

So, I will select the three points for which I will Export the Coordinates to Excel by selecting them in the " click mouse-hold the mouse and drag it-drop" system to include them in a selective rectangle. Of course you can select (highlight) the point by point.
Select Multiple Points in AutoCAD

After the selection has been completed, it is necessary to specify the Folder or New Folder in which we will capture the CSV file and name it with some meaningful name that we will later be aware of.
Export Coordinate to Excel from AutoCAD

Now let's open the captured file and see in the open file a List of Coordinates from AutoCAD where we are A=X i B=Y axis

View Coordinates in AutoCAD

Check Coordinates in AutoCAD

View Coordinates in Excel

Coordinate List in Excel

Comments

Popular posts from this blog

24d. Plot in Color Thickness Lines

24c. Ucsfollow Command Rotate Drawing