Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

fuccaro,

 

thanks for the help. this works nicely!

 

What does the while-loop use to end the looping?

 

msm54

Posted

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.

Posted

Never mention it. It was my pleasure!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...