I am looking for help with a routine that will run the TIME command and then take the resulting text and save it to a file.
Ideally, the text file should be named based on the drawing name.
I know there's ways to write text to a file but I haven't had any luck taking the output of a command and exporting it.
Any help would be greatly appreciated!
Thank you,
t.k.
Solved! Go to Solution.
Solved by Lee_Mac. Go to Solution.
As an insight, the TIME command is merely a convenient way to display the System Variables: DATE, TDCREATE, TDINDWG, TDUPDATE & TDUSRTIMER.
These System Variables are stored as Julian Dates, which is great for data storage, since an elapsed time can be stored as a single standardised number, however, not so great if you want to immediately see how these figures relate to the Day, Month and Year.
Hence the TIME command conveniently formats these values to make them readable.
Thankfully, the DIESEL language offers the edtime function. This useful function provides the ability to format a Julian Date according to a supplied picture.
Hence, to obtain the Total Editing Time (TDINDWG) as a string formatted in the same way as the TIME command, we could use something like:
(menucmd "m=$(edtime,$(getvar,TDINDWG),HH:MM:SS:MSEC)")
Or, to return the current date/time (DATE😞
(menucmd "m=$(edtime,$(getvar,DATE),DD MONTH YYYY HH:MM:SS:MSEC)")
Of course, repeated usage of the menucmd function may warrant the creation of a dedicated subfunction to avoid repetitive typing, so perhaps we could construct something like:
(defun FormatDate ( sysvar format ) (menucmd (strcat "m=$(edtime,$(getvar," sysvar ")," format ")")) )
Now, we can retrieve say, the Last Updated data (TDUPDATE), using:
(FormatDate "TDUPDATE" "DD MONTH YYYY HH:MM:SS:MSEC")
With these tools at our disposal, the difficult part is all done. Now we are just left to write the data to a file of our choice.
For this task, consider the following function:
(defun c:timeout ( / filename openfile ) (if (setq openfile (open (setq filename (GetUniqueFilename (strcat (getvar 'DWGPREFIX) (cadr (fnsplitl (getvar 'DWGNAME))) "_TIME.txt" ) ) ) "w" ) ) (progn (foreach item '( ("Current time:" "DATE" "DD MONTH YYYY HH:MM:SS:MSEC") ("Created:" "TDCREATE" "DD MONTH YYYY HH:MM:SS:MSEC") ("Last updated:" "TDUPDATE" "DD MONTH YYYY HH:MM:SS:MSEC") ("Total editing time:" "TDINDWG" "HH:MM:SS:MSEC") ("Elapsed timer:" "TDUSRTIMER" "HH:MM:SS:MSEC") ) (write-line (strcat (PadRight (car item) " " 24) (apply 'FormatDate (cdr item)) ) openfile ) ) (close openfile) (startapp "notepad" filename) ) (princ (strcat "\nUnable to Write to " filename)) ) (princ) ) (defun PadRight ( string char lengtth ) (if (< (strlen string) lengtth) (PadRight (strcat string char) char lengtth) string ) ) (defun GetUniqueFilename ( seed / count file flist ) (if (findfile (setq file seed)) (progn (setq count 1 flist (fnsplitl seed) ) (while (findfile (setq file (strcat (car flist) (cadr flist) "(" (itoa (setq count (1+ count))) ")" (caddr flist) ) ) ) ) ) ) file ) (defun FormatDate ( sysvar format ) (menucmd (strcat "m=$(edtime,$(getvar," sysvar ")," format ")")) )
That could be a very basic form of what you may be looking to achieve. It would need some minor modification should you want to display the 'days' elapsed, but I shall leave that as an exercise for you.
I hope this helps you towards your goal.
Lee
Very nice post Lee, coincidently there's a similar post on another forum. Would be so kind as to helped the OP out. that will save me time composing a code or suggesting a whole lot of different apporach arriving at the same result as the one above . or should i just direct the OP here?
or maybe im just being lazy again ....
Thanks pBe I think I know the thread you are referring to - just direct them here if it helps.
I can't say "Thank you" enough Lee Mac!
Thank you for spending the time to explain your process and the logic. The routine works exactly how I hoped it would.
I am always surprised at the depth of support provided by people on this forum. Your expertise is most appreciated.
Thank you so very much!
-t.k.
You're very welcome thomk!
I enjoyed writing the explanation and am glad that it can help you. If there is anything that you don't understand from my code, just ask.
Cheers,
Lee
I found this Lisp routine to be very helpful ! Would anyone have any input re: modifying this program so that it would provide the same info for a few hundred drawings and also provide the LogInName without having to open each of the drawings?
Thanks ! ! !
As far as I can went , LOGINNAME is not SAVED at the dwg
It´s from the ACAD help
(Read-only)Type: String
Saved in: Not-saved
Initial value: ""
Displays the user's name as configured or as input when the program starts. The maximum length for a login name is 30 characters.
@putitonpaper wrote:
I found this Lisp routine to be very helpful ! Would anyone have any input re: modifying this program so that it would provide the same info for a few hundred drawings and also provide the LogInName without having to open each of the drawings?
Thanks ! ! !
That will be a bit tricky [this part --> "without having to open each of the drawings"].
Not sure ODBX will work as the routine uses 'getvar function, os that idea is out of the window
With script you need to open the file
We can however use (vlax-create-object "Shell.Application") to get these information:
Drawing Name
Date Modified
Date Created
Date Accessed
Owner <--- the last USER to read/saved the file
All this without opening a single file
Will that work for you?
ODBX can not give the "edtime" , edtime give the data from the open sesion.
It is what I get.
("D:\\Perfil NO BORRAR\\Mis documentos\\ghetyuiopl.dwg"
"Current time: 20 February 2012 11:50:26:453"
"Created: 20 February 2012 11:48:13:077"
"Last updated: 20 February 2012 11:48:13:077"
"Total editing time: 00:02:13:422"
"Elapsed timer: 00:02:13:374"
"LOGINNAME Usuario")
The attached pdf , show the propierties form the window explorer
@devitg wrote:ODBX can not give the "edtime" , edtime give the data from the open sesion.
Exactly, That's what i'm afraid of Devtg, thank you for confirming that.
"Not sure ODBX will work as the routine uses 'getvar function, so that idea is out of the window"
Now with apporach i'm suggesting using File properties would work but without the
Total editing time: Elapsed timer: , I guess we can write a cdoe for that.
anyhoo...lets wait for the putitonpaper to agree with that suggestion, till then... i'm going to sit on it for now
Cheers
I copied the "timeout" code and tried it out.
I noticed that it creates a separate .txt file for each time it is run.
(I got rid of the :MSS part, and it works fine for whole seconds, I might even get rid of the seconds, too. Minutes is close enough)
What I was searching the forums for, was a way to save the open/close/save history of a particular drawing file.
I am working on a project, but it is taking longer than expected (Really?). I tried to go back through my mind and record my hours over the past two weeks - to no avail.
I looked at the issue in AutoCAD, and found the "logfileon / off" function, but who needs to see ALL the commands that have gone by?
I also looked into my autosave folder, but only a few of the autosave files are still there. Does AutoCAD erase them upon exit? Can I change that? (I always autosave every 9 minutes)
What I would like to see, is a way to automatically record the date & time each time a drawing is opened, and then closed, all in the same file, in the same folder with the drawing.
Just opened, then closed, in a continuing log file, without all the command history.
Of course, that would not account for extended times the drawing is idle, but still open.
I'm thinking a bit of code tacked into the acaddoc file, to record the open time, then a bit of code attached to the close function, either with a special command macro, or through the actual close command.
I only know the (defun C: ) part of lisp, for making keyboard shortcut command combinations.
Please bear in mind that I am stuck using AutoCAD version 2004, so no newer commands than that!
Thanks in advance,
Frank