I forgot to tell that when reading a list from a file
with (read_list_from_file) the returned value is a
string. Although this can be of some interest for
some particular situations, like passing it to an
(alert (read_list_from_file))
call for debugging purposes, you will need to use
(read (read_list_from_file))
in order to get a real list.
"Constantin Gherasim" a écrit dans le
message de news: 5260704@discussion.autodesk.com...
Hi eagledon,
Here is an old trick to write/read a list to/from a file. As you can see
this keeps the list as a list.
(defun write_list_to_file (my_list / file_handle)
(setq file_handle (open "c:\\lsptest.txt") "w"))
(prin1 my_list file_handle)
(close file_handle)
(princ)
)
(defun read_list_from_file ( / file_handle my_list)
(setq file_handle (open "c:\\lsptest.txt" "r"))
(setq my_list (read-line file_handle))
(close file_handle)
my_list
)
If you want it each element on a new line then use the next one:
(defun C:EXPRT2F ( / file_handle selset counter name)
(setq file_handle (open "c:\\lsptest.txt" "w"))
(setq selset '(a b 2 5 d 9 2 kd 9 8))
(setq counter 0)
(repeat (length selset)
(setq name (nth counter selset))
(if (= counter 0)
(princ name file_handle)
(print name file_handle)
)
(setq counter (1+ counter))
)
(close file_handle)
(princ)
)
Regards,
Constantin
a écrit dans le message de news:
5259839@discussion.autodesk.com...
This is a MODIFIED piece of code I found here:
http://discussion.autodesk.com/thread.jspa?messageID=1168520
Using AutoLISP, I need to be able to write a list to file, but this code
does not seem to work.
Any tips?
(defun C:EXPRT2F ( / fname selset txt cnt nme)
(setq fname "c:\lsptest.txt")
(setq selset '(a b 2 5 d 9 2 kd 9 8))
(setq txt (open fname "w") cnt 0)
(repeat (length selset)
(setq nme (nth cnt selset))
(write-line nme txt)
(setq cnt (1+ cnt)) )
(close txt) )