Hello, The lisp above get a list of points from a external text file. The text file: Note: first line blank, but I know -258.93622987,491.24957137,0 -234.88776544,510.42857069,0 -252.62047217,514.07015255,0 -274.48271257,489.55016572,0 -292.2154193,493.19174757,0 -274.48271257,492.46343199,0 -292.2154193,496.10501384,0 -274.48271257,504.35926761,0 -292.2154193,508.00084946,0 -274.48271257,510.42857069,0 -292.2154193,514.07015255,0 Results a list of coordinates: ((-258.936 491.25 0.0) (-234.888 510.429 0.0) (-252.62 514.07 0.0) (-274.483 489.55 0.0) (-292.215 493.192 0.0) (-274.483 492.463 0.0) (-292.215 496.105 0.0) (-274.483 504.359 0.0) (-292.215 508.001 0.0) (-274.483 510.429 0.0) (-292.215 514.07 0.0)) How to draw points from a list of coordinates? Thanks, Rogério (defun C:GETPTLIST (/ F STR PT PLIST FSETQ COMMA CHAR I STR2 X STR1 COUNT Y Z ) (setq fn (getfiled " Open points file (.txt)" "" "txt" 8) f (open fn "r") str (read-line f) plist nil ) ;_ end of setq (while (/= str EOF) (setq str (read-line f)) (if str (progn (setq pt (get-pt str)) (setq plist (append plist (list pt))) ) ;_ end of progn ) ;_ end of if ) ;_ end of while (setq f (close f)) plist ) ;_ get-ptlist (defun get-pt (str1) (setq comma (chr 44) str2 "" count 1 i 0 ) ;_ end of setq (repeat 2 (repeat (strlen str1) (setq char (substr str1 (setq i (1+ i)) 1)) (if (/= char comma) (setq str2 (strcat str2 char)) (progn (if (= count 1) (progn (setq x (atof str2)) (setq str1 (substr str1 (1+ i))) (setq i 0) (setq count 2) (setq str2 "") ) ;_ end of progn (progn (setq y (atof str2)) (setq str1 (substr str1 (1+ i))) (setq z (atof str1)) ) ;_ end of progn ) ;_ end of if ) ;_ end of progn ) ;_ end of if ) ;_ end of repeat ) ;_ end of repeat (setq pt (list x y z)) ) ;_ end of get-pt
Unless you need to retain the list of coordinates in a LISP variable, your code is vastly over-complicated. Just do this: (setq file (open "filename.txt" "r")) (while (setq line (read-line file)) (command "._point" line) ) That's all there is to it. Here's another tip: If you need to convert your coordinate strings from the file, to a point list, here's an easier way to do it: (defun read-coordinate (coordstr) (command "._LASTPOINT" coordstr) (getvar "lastpoint") ) Pass the above a string in the form "xxx.xxx,yyy.yyy,zzz.zz" and it returns a 3 element coordinate list. If you call this many times and depend on the current value of LASTPOINT, you should save/restore it before/after you use this code.