• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Visual LISP, AutoLISP and General Customization

    Reply
    Distinguished Contributor
    The_Caddie
    Posts: 140
    Registered: 06-08-2010
    Accepted Solution

    How to append to textfile and record the date variable (code needs checking)

    52 Views, 2 Replies
    02-22-2012 08:00 AM

    I have forgotten how to append I’m assuming its not write-line but append line could somebody confirm this.

     

    And also

     

    I’m having trouble recording the date variable… I keep getting error bad argument type stringp nil

    		; Appends usage count by DATE long variable...
    		(setq g(open "C:/ICT/AutoCAD_Architecture_suite_2012/CUSTOM/WOOD Clones/PEN/USSAGELOG.PEN" "w"))
    		(setq MYDATE DATE)
    		(write-line MYDATE g)
    
    		; AS ABSOLUTE LAST WE NEED TO CLOSE THE TEXTFILE...
    		(close g)
    
    I have the following code snippet I’m trying to append the file named USAGELOG.TXT to record the date of executions

     

    Mentor
    Posts: 272
    Registered: 03-15-2007

    Re: How to append to textfile and record the date variable (code needs checking)

    02-22-2012 08:14 AM in reply to: The_Caddie

    Maybe this change "w" to "a"

     

    (setq g(open "C:/ICT/AutoCAD_Architecture_suite_2012/CUSTOM/WOOD Clones/PEN/USSAGELOG.PEN" "w"))

     

    (setq g(open "C:/ICT/AutoCAD_Architecture_suite_2012/CUSTOM/WOOD Clones/PEN/USSAGELOG.PEN" "a"))

     

    Southie

    Mentor
    Posts: 299
    Registered: 11-26-2007

    Re: How to append to textfile and record the date variable (code needs checking)

    02-22-2012 08:24 AM in reply to: southie

    Changing 'w' to 'a' appends the file instead of overwriting.  If you want to append lines in the file you'll have to read the entire file and save them to variables.  Then append them with code and write everything back to the file.

    ---sig---------------------------------------
    '(83 104 110 101 117 112 104 64 71 109 97 105 108 46 99 111 109)