Please help me modify the lisp program for importing the data from .txt
This is how data looks like:
the first number is object code, second is X coordinate and third is Y
I need program to draw SEPERATE objects with data like that.
Firstly the data has an error in the first line 2.117.428999999954 should
read 2117.428999999954 The first decimal is incorrect. Next consider the
attached lisp routine:
(defun initiate ()
fileopen (open (findfile filename) "r")
(defun c:separate ()
line (read-line fileopen)
delimiter1 (vl-string-search "," line)
delimiter2 (vl-string-search "," line (1+ delimiter1))
dat1 (substr line 1 delimiter1)
dat2 (substr line (+ 2 delimiter1) (1- (- delimiter2 delimiter1)))
dat3 (substr line (+ 2 delimiter2))
coord (list (distof dat2) (distof dat3))
This routine assumes your data file is named data.txt . You can change this
by changing the filename variable.
Assuming the data file is in your AutoCAD search path, to run this load it
and then enter "separate" without the quotation marks.
The first line of the data file will be broken up into 5 entities dat1,
dat2, dat3, codeno & coord. dat1=codeno=dat1. dat2=xcoordinate as a string.
dat3=ycoordinate as a string & finally coord is the list of your x and y
coordinates which can be used by AutoCAD. for example if you wish to draw a
line from the first coordinate point type in "l" to start the line command
and then !coord to use the coordinate as the first point.
To retrieve subsequent data lines just run "separate" again. When you are
done enter (close fileopen) at the command line. To start over enter (close
fileopen) then (initiate) then "separate".
Jeff, there are two problems with your program; it doesnt work if the
start object code is NOT = 1 and if any object is skipped.
Could you please modify it so it would work with this data file:
being slow is not actually a big problem, I can live with that
I sometimes have to visualize in 3D a surface having as many as 3/4
million elevation points. " Living with that " in acad would represent
a significant portion of my life.
If you do find you need help getting around this at some future point
- hahaha - post again.
I thought you'd forgotten about this since there was no response for 11
days. I'll take a look at it in the next day or two.
Would you be willing to send me a complete point file? If so, send to:
jmishlerATsbcglobalDOTnet adjust the AT & DOT accordingly
I just looked and realized it wasn't too hard of a fix. Here's a new lisp
that works with any leading number, in any sequence (providing the same
number sequence is not repeated, otherwise they will be all created as 1
This one also should be much quicker.
;|requires data file in the format of:
by Jeff Mishler March 11, 2006
(defun c:data2plines (/ dat dat_list ffile fname idx master tmp mspace
;;Str2List function by John Uhden as posted to the Adesk newsgroups
(defun Str2List (str pat / i j n lst)
((/= (type str) (type pat) 'STR))
((= str pat) '(""))
(setq i 0
n (strlen pat)
(while (setq j (vl-string-search pat str i))
(setq lst (cons (substr str (1+ i) (- j i)) lst)
i (+ j n)
(reverse (cons (substr str (1+ i)) lst))
(if (setq fname (getfiled "Data File Selection" "" "" 0))
(setq ffile (open fname "R"))
(while (setq dat (read-line ffile))
(setq dat_list (str2list dat ","))
(setq master (cons (list (atoi (car dat_list))
(atof (cadr dat_list))
(atof (caddr dat_list))
(setq master (reverse master)
(setvar "osmode" 0)
(setq idx (car (car master))
(setq tmp (vl-remove-if-not '(lambda (x)
(= (car x) idx)
(setq coords (apply 'append (mapcar 'cdr tmp)))
(setq pline (vlax-invoke mspace 'addlightweightpolyline coords))
(vla-put-closed pline :vlax-true)
(setq master (vl-remove-if '(lambda (x)
(= (car x) idx)
If you take your *.txt file and rename it to *.csv it will open in
Excel. If you add two columns in Excel, Z coordinate and Description
could make use of our survey program:
It's an add-on VB program which imports and exports survey data to &
from AutoCAD. The download is fully functional and free to use for 30 days.
From the website:
Survey Import and Export
The Survey program works to Import and Export your survey data to and
from AutoCAD®. The configurable interface makes matching survey data
descriptions (as assigned in the field) to text, blocks or points,
Import Survey Data:
Survey data is read from *.txt or *.csv file(s) so the user may match
the data to blocks, text or points per unique description. The selected
descriptions are inserted in to the drawing per the symbols specified
(with the option of coordinate marker blocks, which display coordinate &
other data). Import Survey Data works with the supplied database
(CADD.mdb included with the program's installation file) to support
multiple (saved) import configurations.
Export Survey Data:
Blocks and text are exported from the drawing to a text file (containing
X, Y, Z, Index and Description) via a configurable interface.
Hope this helps,
Hi, could you do one more modification, hope its not too hard:
the new data would look like this:
LineCode, Xcoordinate_of_first_dot, Ycoordinate_of_first_dot,
ASCIItext, line density
LineCode, Xcoordinate_of_next_dot, Ycoordinate_of_next_dot,, line
this time Line must NOT be closed, I have tried modifying your program
(vla-put-closed pline :vlax-true) to
(vla-put-closed pline :vlax-false)
and it works, but how can I add ASCII text next to line and change its