TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Hangman 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.
(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
"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
(defun SaveDrawing (/ )
(setq FNnote (open FNnotePath "R")
NewFName (read-line FNnote)
...
The variable 'NewFName' is this
"\"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.
-
You are missing the file pointer in your write-line expression:
(write-line crntFName)
I would use something like this:
(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:
C:\YourFolder\YourDrawing.dwg
Which can then be read using something like:
(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:
"C:\\YourFolder\\YourDrawing.dwg"
Your post indicates you are using either prin1/print or vl-prin1-to-string when writing your filename string.
Lee