PDA

View Full Version : import text file values


KHADREE_SHARIFF
2007-06-25, 08:40 AM
please try to help me in giving tips to develop the following algorithm....
1) i am having a set of dimension which i had exported to a text file (.txt)
Example:-
150
115
6350
235
365
7000
....
....
....

now i want to use these values in another routine with some calculations.
my problem is how to read these values, name them & import to routine
Example:-
(SETQ A (150)
B(115)
C(6350)
....
....); upto 'n' numbers
2) can we use the above text values in a script & assign to a autolisp routine with
a dialog box ( i tried to call a lisp routine in a script but i am not able to assign values to a dialog box)

abdulhuck
2007-06-25, 10:05 AM
now i want to use these values in another routine with some calculations.
my problem is how to read these values, name them & import to routine

Hi,

With the following code, you can retrieve the values to a list and perform calculations with each value in the list.

(defun c:readfile (/ txtfile fileid datalist linedata count)
(setq txtfile (getfiled "Select text file" "c:\\" "txt" 8 ))
(setq fileID (open txtfile "r"))
(setq datalist '())
(while (setq linedata (read-line fileID))
(setq datalist (append (list linedata) datalist))
); while
(close fileid)
(setq datalist (reverse datalist))
(setq count 0)
(foreach item datalist
(setq item (nth count datalist))
(princ item)(terpri) ; print output (remove when finished)
;;; convert text into a real number
(atof item)
;;; then perform your calculations here
;;;
(setq count (1+ count))
) ; foreach
(princ)
); defun


Regards
AbdulHuck