Author Topic: Help writing a simple lisp!  (Read 170 times)

0 Members and 1 Guest are viewing this topic.

Vikram

  • Newt
  • Posts: 29
Help writing a simple lisp!
« on: December 31, 2019, 02:44:35 AM »
I'm new at lisp programming and I need a lisp which will write the coordinates of the points which I select.However  the lisp I wrote only writes one coordinate at a time in text file. i want it to write in the file as I select points. Right now it only writes the last point I selected.

Code: [Select]
(defun c:test (/ p x y)
 (while
   (setq p (getpoint "\nPick Point: "))
    (setq fileName "C:\\Users\\Developer\\Desktop\\cir.txt")
    (progn (setq filename (open filename "w"))
                (write-line (strcat (rtos (car p) 2) "\t" (rtos (cadr p) 2) "\t") fileName)
                ;;;(write-line (strcat (rtos (car pt2) 2) "\t" (rtos (cadr pt2) 2) "\t" (rtos (caddr pt2) 2)) fileName)
           
           (close fileName)
    )
    (princ)
 )
)

Dlanor

  • Newt
  • Posts: 188
Re: Help writing a simple lisp!
« Reply #1 on: December 31, 2019, 04:22:52 AM »

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ fp p)
  2.   (setq fp (open "C:\\Users\\Developer\\Desktop\\cir.txt" "w"))
  3.   (while (setq p (getpoint "\nPick Point: "))
  4.     (write-line (strcat (rtos (car p) 2) "\t" (rtos (cadr p) 2) "\t") fp)
  5.   )
  6.   (close fp)
  7.   (princ)
  8. )
  9.  

Vikram

  • Newt
  • Posts: 29
Re: Help writing a simple lisp!
« Reply #2 on: December 31, 2019, 05:14:47 AM »
Ah! It was so easy!
Thanks for the help and your time! :smitten: