There is often the need to import and export points in AutoCAD. Despite the fact that Civil 3D has an integrated tool for this kind of work, AutoCAD doesn’t. But, don’t be disappointed or try doing this thing manually. There are some ways to import and export points from AutoCAD too, even if we have to use some DIY stuff.
There are 2 easy ways to achieve this. First of all, let’s say that you have some points in a txt file. Strip it down so there are only the Xs and the Ys (every point should have it’s coordinates in a separate line). Something like 4822.92, 8709.21
Then you have to add the word POINT in every line between the numbers at the beginning of the list (before the first set of coordinates). Then save the file but replace the extension .txt or. csv to .SCR. What you did was that you created a script file that tells AutoCAD to use the command POINT with the coordinates that follow each command. The program will go through every line until the end, creating points of the coordinates provided.
*An easy way to insert the word POINT in every line is by using the Notepad++ app (the best notepad application). The pictures bellow show how it is done step by step.First, you have to press CTRL+F, then go to the replace tab and type \r at the “Find What:” space and \nPOINTS at the “Replace With:” space. Then hit replace all and the word POINT would be inserted in every line between the coordinates. Have in mind that you have to type POINT manually before the first line of coordinates.
The second way is by using AutoLISP scripts. I have written one and it’s very easy to understand. All you have to do is to have a file with X,Y coordinates. As it is a very basic script, I didn’t add any error check or point numbering etc. The script is the one bellow:
(defun c:impo (/ filepath rline dir file filename) (setq filepath(getfiled "PICK YOUR POINT FILE" "C:/" "txt" 4)) (setq rdfl (open filepath "r")) (while (setq rline (read-line rdfl)) (command "POINT" rline) (princ) ) )
Just copy it to a notepad file and rename it’s extension to “.LSP”. The way you can load LISP programs to AutoCAD is here.The script runs by typing IMPO command in AutoCAD.
In the past I have written a LISP script that allowed the user to export points to a file. It can be found here . Recently, I changed the code of this script and I am using the command “getfiled” that allows the user to select where to create the file in a visual way. The code is the following and is very basic (no error check etc) and the script runs by typing POUT command in AutoCAD:
(defun c:pout (/ a filename TargetFile i i2 exitmsg) (setq filename (getfiled "NAME THE EXPORT FILE" "c:/Users/Public/Documents/" "txt" 1)) (setq TargetFile (open filename "a")) ;open file to write (append) (write-line "Point Number,X,Y,Z" TargetFile) ;Collecting the points (setq i 0) ;set i as zero (this is the counter) (while (setq a (getpoint "\nTick the Point")) ;select points (setq x (rtos(car a))) ;get as X the x of a point (as string) (setq y (rtos(cadr a))) ;get as Y the y of a point (as string) (setq z (rtos(caddr a))) ;get as Z the z of a point (as string) (setq i (1+ i)) ;in each loop the counter is added by 1 (setq i2 (itoa i)) (setq pnt (strcat i2 "," x "," y ","z)) (write-line pnt TargetFile) ) ;while end (princ) (close TargetFile) ;close the file ;Message of the saved file (setq exitmsg (strcat "Your file is saved as " filename " Written by Antonis Raftopoulos," " email@example.com, https://hedproject.wordpress.com")) ) (princ exitmsg)