Author Topic: help writing selected lines to file  (Read 2367 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
help writing selected lines to file
« on: July 30, 2009, 10:43:20 AM »
im tried to modify this lisp to instead of opening a selected dwg
i want it to add selected lines of the file it read to another file

ive seen this explained here before but search isnt turning up anything
can anyone guide me?

TIA


andrew_nao

  • Guest
Re: help writing selected lines to file
« Reply #1 on: July 30, 2009, 10:43:56 AM »
oops here is the dcl file


Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: help writing selected lines to file
« Reply #2 on: July 30, 2009, 11:41:47 AM »
You should look at the following lisp functions in the help file. Everything you need to know about writing stuff to a file can be found there.

  • OPEN
  • READ-CHAR
  • READ-LINE
  • WRITE-CHAR
  • WRITE-LINE
  • CLOSE
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

andrew_nao

  • Guest
Re: help writing selected lines to file
« Reply #3 on: July 30, 2009, 03:36:04 PM »
Thanks for the reply
Im looking for guidance on writing multple selected lines to a file
i can get 1 line to write to a file no problem

but adding multiple lines at once to a file is what my issue is
everything i try i get bad argument type stringp

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: help writing selected lines to file
« Reply #4 on: July 30, 2009, 03:40:22 PM »
For multiple lines, just invoke write-line multiple times, maybe through mapcar, foreach or while, for example:

Code: [Select]
(mapcar
  (function
    (lambda (x)
      (write-line x file))) '("Hello" "Andrew" "Nao"))

Code: [Select]
(foreach str '("Hello" "Andrew" "Nao")
  (write-line str file))

Code: [Select]
(setq lst '("Hello" "Andrew" "Nao"))
(while (setq str (car lst))
  (write-line str file)
  (setq lst (cdr lst)))

« Last Edit: July 30, 2009, 04:14:41 PM by Lee Mac »

andrew_nao

  • Guest
Re: help writing selected lines to file
« Reply #5 on: July 30, 2009, 03:55:51 PM »
For multiple lines, just invoke write-line multiple times, maybe through mapcar, foreach or while, for example:

thanks Lee, ill give this a try

but what i was thinking was somehow i have to get my multiple lines into a list and then i could use foreach function

my selection is coming from a DCL list

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: help writing selected lines to file
« Reply #6 on: July 30, 2009, 04:10:53 PM »
You can collect data from a DCL list as described in this tutorial

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: help writing selected lines to file
« Reply #7 on: July 30, 2009, 04:13:21 PM »
If you already have your list, something like this will work

Code: [Select]
(foreach list_item my_dcl_list (write-line list_item my_file))
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

andrew_nao

  • Guest
Re: help writing selected lines to file
« Reply #8 on: July 30, 2009, 04:40:44 PM »
im stupid  :ugly:

i was trying to turn a list into a list
the foreach works
now i have to get the dcl list to update
that info is in here somewhere i remember seeing it

thanks for the help guys