Author Topic: read-line a string ...  (Read 1604 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
read-line a string ...
« on: January 19, 2011, 12:18:12 PM »
Good morning everyone,

I have a dwg I want to overwrite.
So by using code, I am saving the filename and path to an .ini file.
Code: [Select]
(defun SaveFileName (/ crntACADv crntFName crntFPath)
  (prompt "\nSaving File Name ...")
  (setq crntFName (getvar "dwgname")                    ; current file name
        crntFPath (getvar "dwgprefix")                  ; current file path
        crntFName (strcat crntFPath crntFName)          ; put the two together
        FNnote (open FNnotePath "W")                    ; write out to FixDWG_FN.ini
  )
  (write-line crntFName)                                ; "K:\\directory\\sub directory\\filename.dwg"
  (setq FNnote (close FNnote))
  (princ)
) ; _function SaveFileName

So, the .ini file has this
Quote
"K:\\2004-2005 EFM\\Yakima Firing Center\\PM5-YFC-E0002.dwg"

Then after a script is run opening a new template and running a LiSP, the LiSP calls the .ini and reads the line
Code: [Select]
(defun SaveDrawing (/ )
  (setq FNnote (open FNnotePath "R")
        NewFName (read-line FNnote)
 ...

The variable 'NewFName' is this
Quote
"\"K:\\\\2004-2005 EFM\\\\Yakima Firing Center\\\\PM5-YFC-E0002.dwg\""

Why does reading a line from a text file add quotes and backslashes throughout the string?
Do I need to go through this string character for character to clean it up or is there a better formatting way of doing this?

I really appeciate your help and could really use some ideas / code examples of how I could make this little thing work.
Thanks.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: read-line a string ...
« Reply #1 on: January 19, 2011, 12:26:21 PM »
You are missing the file pointer in your write-line expression:

Code: [Select]
(write-line crntFName)
I would use something like this:

Code: [Select]
(defun SaveFileName ( / file )
  (princ "\nSaving Filename...")

  (if (setq file (open FNnotePath "w"))
    (progn
      (write-line (strcat (getvar 'DWGPREFIX) (getvar 'DWGNAME)) file)
      (close file)
      T
    )
  )
)

The string will be written as something like:

Code: [Select]
C:\YourFolder\YourDrawing.dwg
Which can then be read using something like:

Code: [Select]
(defun ReadFileName ( / file line )
  (princ "\nReading Filename...")

  (if (setq file (open FNnotePath "r"))
    (progn
      (setq line (read-line file))
      (close file)
    )
  )
  line
)

Returning something like:

Code: [Select]
"C:\\YourFolder\\YourDrawing.dwg"
Your post indicates you are using either prin1/print or vl-prin1-to-string when writing your filename string.

Lee