- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm working on a lisp to draw lines from coordinates provided in a .txt file. I have gotten it to work from selecting a start point via this code and .txt file contents:
(defun c:test\ ( / path file rline1 rline2 stpoint)
(setq path "c:\\desktop\\test.txt")
(setq file (open path "r"))
(setq rline1 (read-line file))
(setq rline2 (read-line file))
(close file)
(setq stpoint (getpoint "SELECT START POINT > "))
(command "_.line" stpoint rline1 rline2 "")
(princ)
)
my question is how do I loop this? (it can be assumed coordinates will always be in the correct order) I have looked through multiple websites and forums but can't find anything that works or makes sense to me. I have added the "while" function but it breaks the code. Essentially I need it to read every line of a .txt file until there is no content left and make every line it's own individual string for lisp use.
(defun c:test\ ( / path file rline stpoint)
(setq path "c:\\desktop\\test.txt")
(setq file (open path "r"))
(while (setq rline (read-line file)))
(close file)
(setq stpoint (getpoint "SELECT START POINT > "))
(command "_.line" stpoint rline "")
(princ)
)
I could do this manually with the code I have already but would become very tedious since I would need an individual lisp for every possible line situation. For example if I had one that had 16 lines of coordinates i could just use this:
(defun c:test\
( /
path file stpoint rline1 rline2 rline3 rline4 rline5 rline6 rline7 rline8
rline9 rline10 rline11 rline12 rline13 rline14 rline15 rline16
)
(setq path "c:\\desktop\\test.txt")
(setq file (open path "r"))
(setq rline1 (read-line file))
(setq rline2 (read-line file))
(setq rline3 (read-line file))
(setq rline4 (read-line file))
(setq rline5 (read-line file))
(setq rline6 (read-line file))
(setq rline7 (read-line file))
(setq rline8 (read-line file))
(setq rline9 (read-line file))
(setq rline10 (read-line file))
(setq rline11 (read-line file))
(setq rline12 (read-line file))
(setq rline13 (read-line file))
(setq rline14 (read-line file))
(setq rline15 (read-line file))
(setq rline16 (read-line file))
(close file)
(setq stpoint (getpoint "SELECT START POINT > "))
(command "_.line" stpoint rline1 rline2 rline3 rline4 rline5 rline6 rline7 rline8
rline9 rline10 rline11 rline12 rline13 rline14 rline15 rline16 "")
(princ)
)
but that's terrible code and I know it. I would need hundreds of files to account for every situation. The thing that worries me though is even looking at successful "while" functions it seems like it turns the entire list into a single string and that wouldn't work either for this use case.
Solved! Go to Solution.