broncos15 Posted July 11, 2016 Share Posted July 11, 2016 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? Quote Link to comment Share on other sites More sharing options...
rkmcswain Posted July 11, 2016 Share Posted July 11, 2016 (edited) 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 July 11, 2016 by rkmcswain added output Quote Link to comment Share on other sites More sharing options...
broncos15 Posted July 11, 2016 Author Share Posted July 11, 2016 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. Quote Link to comment Share on other sites More sharing options...
broncos15 Posted July 11, 2016 Author Share Posted July 11, 2016 So after looking into a help book I have, I found out the issue. I didn't know that LISP recognized ASCII characters using the chr function. A list of these characters can be found http://www.ascii.cl/htmlcodes.htm for anyone in the future. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 12, 2016 Share Posted July 12, 2016 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))) Quote Link to comment Share on other sites More sharing options...
broncos15 Posted July 12, 2016 Author Share Posted July 12, 2016 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! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 12, 2016 Share Posted July 12, 2016 (princ "\n;; | | Use \"\" for none | | | 0 Quote Link to comment Share on other sites More sharing options...
broncos15 Posted July 12, 2016 Author Share Posted July 12, 2016 (princ "\n;; | | Use \"\" for none | | | 0 Thanks Lee! So the \ has LISP ignore the "? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted July 12, 2016 Share Posted July 12, 2016 Thanks Lee! So the \ has LISP ignore the "? The single backslash is an Escape Character in AutoLISP; see here for more. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.