Author Topic: Question of the day #8  (Read 1580 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Question of the day #8
« on: December 06, 2004, 12:38:42 PM »
Using the previous QOD's code, generate a 'list' of X and Y values from user input. Then write those values to the file the user selected. The pseudo code might look something like this;

prompt user with dialog (getfiled) to select an existing file
start loop for user input (pick point)
   extract 'x' and 'y' values and append to 'list'
end loop
write those values to user selected file
close file
open file with 'notepad' for user examination.
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Question of the day #8
« Reply #1 on: December 10, 2004, 07:44:26 AM »
Code: [Select]

(setq file2open
      (getfiled
"Select text file to open"
(strcat (getenv "USERPROFILE")"\\My Documents\\")
"txt"
8
)
)

(setq cntr 1)
(while
  (setq pt
(getpoint
 (strcat "\nSelect Point for output("(itoa cntr)"): ")
 )
)
  (setq pt_lst (cons (list (car pt) (cadr pt)) pt_lst)
cntr (1+ cntr)
)
  )

(setq pt_lst (reverse pt_lst)
      cntr 1
      )

; append to the file since we are opening an existing one
(setq file_open (open file2open "a"))
(foreach pt pt_lst
(write-line
  (strcat (itoa cntr)","
  (rtos (car pt) 2 3)","
  (rtos (last pt) 2 3)
  )
  file_open
  )
(setq cntr (1+ cntr))
)

(close file_open)

(startapp "notepad" file2open)
TheSwamp.org  (serving the CAD community since 2003)