Author Topic: Need small help in writing a value in a text file  (Read 1320 times)

0 Members and 1 Guest are viewing this topic.

Vikram

  • Newt
  • Posts: 50
Need small help in writing a value in a text file
« on: March 09, 2020, 03:58:30 AM »
I'm writing a lisp in which user selects a point on drawing and then he is asked to enter speed value at that point. When he enter speed value the coordinates of the point and speed value has to be written in a text file. I have written a code but I'm not getting how to write the speed value took from user.
I know it must be pretty easy but I'm a beginner :?

Code: [Select]
(defun c:rollp (/ fp p)
  (setq fp (open (strcat (getvar "dwgprefix")(vl-filename-base (getvar "dwgname")) ".roll") "w"))
  (setq nbs 0)
  (while (setq p (getpoint(strcat "\nPick Speed " (itoa (setq nbs (+ 1 nbs))) " position: ")))
  setq secs (getint "\nSpeed ")
    (write-line (strcat (itoa (setq nbs (+ 0 nbs))) "  X "(rtos (car p) 2) "\t" "Y "(rtos (cadr p) 2) "SPEED" (rtos (secs) 2) "\t") fp)

  )
  (close fp)
  (princ)
)


I'm getting error at variable 'secs'

jtoverka

  • Newt
  • Posts: 127
Re: Need small help in writing a value in a text file
« Reply #1 on: March 09, 2020, 06:49:52 AM »
Code: [Select]
(defun c:rollp ( / *error* fnam nbs secs fp p)
  (defun *error* (msg / )
    (if (not (wcmatch msg "Function cancelled"))
      (progn
        (princ "; error: ")
        (princ msg)
      )
    )
    (if fp
      (setq fp (close fp))
    )
    (princ)
  )
  (setq fnam (strcat (getvar "dwgprefix")(vl-filename-base (getvar "dwgname")) ".roll"))
  (setq fp (open fnam "w"))
  (setq nbs 0)
  (while
    (and
      (setq p (getpoint(strcat "\nPick Speed " (itoa (setq nbs (+ 1 nbs))) " position: ")))
      (setq secs (getint "\nSpeed: "))
    )
    (write-line (strcat (itoa (setq nbs (+ 0 nbs))) "  X "(rtos (car p) 2) "\t" "Y " (rtos (cadr p) 2) " SPEED " (rtos secs 2) "\t") fp)
  )
  (setq fp (close fp))
  (princ)
)

Vikram

  • Newt
  • Posts: 50
Re: Need small help in writing a value in a text file
« Reply #2 on: March 11, 2020, 06:44:28 AM »
Thanks for the help!    :-)