Originally Posted by
fletch97
Since I tried creating a txt file and it still didn't work for me, should we try having the lisp create the file instead?
Give this a try (comments in red, changes in bold red):
Code:
(defun lispWillStart (cmdData lstCallbacks /
dscFile strLogFile strCommandName
lstCommands strDate
strDay strDayText strLogin
strMonth strOutput strTime
strVersion strYear
)
(setq lstCommands '("C:EXP" "C:LYR" "C:PROBE" "C:LYRUP" "C:SPR")
strLogFile "C:/Lisp-Count.csv"
strCommandName (strcase
(substr
(car lstCallbacks)
2
(1- (if (vl-string-search " " (car lstCallbacks))
(vl-string-search " " (car lstCallbacks))
(vl-string-search ")" (car lstCallbacks))
)
)
)
)
)
;;only check for LISP
(if (member strCommandName lstCommands)
(progn
;;if the file is found...
(if (findfile strLogFile)
;;...set strOutput to a zero-length string
(setq strOutput "")
;;...else, set it to use a header
(setq strOutput "LISP,Username,Date/Time,AutoCAD Version\n")
)
(setq strVersion (getAcadVersion)
strDayText (menucmd "M=$(edtime, $(getvar,date),DDDD)")
strTime (menucmd "M=$(edtime, $(getvar,date),hh:mm:ss)")
strMonth (menucmd "M=$(edtime, $(getvar,date),MOnth)")
strDay (menucmd "M=$(edtime, $(getvar,date),DD)")
strYear (menucmd "M=$(edtime, $(getvar,date),yyyy)")
strDate (strcat strDayText ", " strMonth
" " strDay ", " strYear
" " strTime
)
strLogin (getvar "loginname")
;;append the information to the strOutput
strOutput (strcat strOutput
"\"" (car lstCallbacks)
"\",\""
strLogin
"\",\""
strDate
"\",\""
strVersion
"\""
)
)
(setq dscFile (open strLogFile "a"))
(write-line strOutput dscFile)
(close dscFile)
)
)
)
Also, one thing I just thought of, what would happen if the file were already open? If it is open with Notepad, everything would still be fine; Notepad does not mark a file as read only. However, if it is open in Excel, the file could not be written to.