msm54 Posted April 8, 2009 Posted April 8, 2009 I'm trying to write a short routine that starts the "pline" command then reads a comma delimited file for each point desired on the pline. The file exists, contains 200-x,y coordinates (eg. 0,0) My code is: (defun c:drawfoil () (setq f (open "c:/NACA 1212 100points.txt" "r")) ;-Opens the file to read (command "_pline" dataline "") (command "LINE" strtpt endpt "") (while (/= dataline "EOF") ;-Loop until the end of file (setq dataline (read-line f)) ;-Reads a data line ) (close f) ;-Close the file ) The command line looks like: Command: (load "drawfoil") C:DRAWFOIL Command: drawfoil _pline Specify start point: EOF Invalid point. ; error: Function cancelled Specify start point: *Cancel* It appears the pline command is happening but I'm getting the "EOF" that I've inserted at the end of the file to stop the looping. What happened to the 200 x,y coordinates that I know exist in this text file? Any help is appreciated. msm54 Quote
fuccaro Posted April 8, 2009 Posted April 8, 2009 Welcome in the forum! (defun c:test () (setq f (open "c:/test.txt" "r")) ;-Opens the file to read (setq dataline (read-line f)) (command "_pline" dataline) (while dataline (command dataline) (setq dataline (read-line f)) ) (command "") (close f) ;-Close the file ) An advice: turn off OSNAP while runing it Quote
msm54 Posted April 8, 2009 Author Posted April 8, 2009 fuccaro, thanks for the help. this works nicely! What does the while-loop use to end the looping? msm54 Quote
fuccaro Posted April 8, 2009 Posted April 8, 2009 A variable can be NIL or ... something else (not NIL). If there is data in DATALINE, there is not NIL so the loop goes on. When the file ends, the read will return nothing so DATALINE will hold NIL making it stop. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.