Jump to content

Writing Multiple lines of text to a text file


broncos15

Recommended Posts

I had a quick question in regards to writing lines of text to a text file. The end goal is that I am modifying Lee Mac's layer director file found at http://www.lee-mac.com/layerdirector.html so that based on the user's settings, it will read the commands for the reactor to work on from either the default in the LISP, or a user defined txt file that would be saved on their computer. The routine would automatically write the text file to the default location (i.e. C:\\), and then the user could enter in their defaults in the txt file. I understand the basic concept of how to do this, but I have difficulties in trying to write multiple lines as well as how to write the ";" character because AutoCAD keeps recognizing this as commented out. Does anyone have any suggestions?

Link to comment
Share on other sites

Can you post what you have so far?

 

Does this help?

 


(setq fn "C:\\temp\\output.txt"
     fp (open fn "w")
)
(princ "line 1" fp)
(princ "\nline 2" fp)
(princ "\nline 3" fp)
(princ (strcat "\n" (chr 59) " comment" ) fp)
(close fp)
(startapp "notepad" fn)

 

The resulting text file =

line 1
line 2
line 3
; comment

Edited by rkmcswain
added output
Link to comment
Share on other sites

Can you post what you have so far?

 

Does this help?

 


(setq fn "C:\\temp\\output.txt"
     fp (open fn "w")
)
(princ "line 1" fp)
(princ "\nline 2" fp)
(princ "\nline 3" fp)
(princ (strcat "\n" (chr 59) " comment" ) fp)
(close fp)
(startapp "notepad" fn)

The resulting text file =

line 1
line 2
line 3
; comment

rkmcswain thank you so much for the help! I figured out what my issue is. In one of my lines of code I have
(princ "\n;;                   |                |     Use "" for none     |              |              |  0 <= int <= 211 |  0 = Won't Plot  |  Use nil for CTB ;;" file_open)

The issue is that I have "" in the center portion of it. I cannot figure out what chr value is used for the quotation, which I am trying to use with strcat.

Link to comment
Share on other sites

Page 237 & 238 in your Autocad Release 12 Autolisp Programmers manual

 

(setq ans (Getstring "\nEnter single keyboard character"))
(Alert (strcat "For " ans " the code number is " (rtos (ascii ans) 2 0)))

(setq x (Getint "\nEnter single keyboard number"))
(Alert (strcat "For " (rtos x 2) " the alpha code is " (chr x)))

Link to comment
Share on other sites

Page 237 & 238 in your Autocad Release 12 Autolisp Programmers manual

 

(setq ans (Getstring "\nEnter single keyboard character"))
(Alert (strcat "For " ans " the code number is " (rtos (ascii ans) 2 0)))

(setq x (Getint "\nEnter single keyboard number"))
(Alert (strcat "For " (rtos x 2) " the alpha code is " (chr x)))

Thanks BigAL, that is a really nice reference code to have!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...