alanjt Posted April 14, 2010 Posted April 14, 2010 I seriously do not recommend you have this set to auto on. If you open a file, just to take something from it, print, etc. you will have to remember to turn the reactor off; otherwise, you will be changing the edit date of the file. This may not be a big deal to you, but you really should be aware it. Please heed my advice. Quote
chulse Posted April 14, 2010 Author Posted April 14, 2010 I seriously do not recommend you have this set to auto on. If you open a file, just to take something from it, print, etc. you will have to remember to turn the reactor off; otherwise, you will be changing the edit date of the file. This may not be a big deal to you, but you really should be aware it. I thought about that... I was just thinking if there would be a way to check if the user wanted to save the DWG, or possibly check if the user had saved the dwg in the last 5 min or something... Any thoughts? The goal here was to prevent users from closing a dwg they were working on without reverting the UCS to World first. This is intended to prevent xrefing problems... Quote
Glen Smith Posted April 14, 2010 Posted April 14, 2010 It looks like you are most of the way to where you want to be, but I just wanted to toss another option out there. I have a macro on a button in a toolbar: "Zoom Save Close". It zooms extents on both model and paper space, locks the viewports, saves the drawing and closes it. You could write one that would set the UCS to World. This way, you can still exit the drawing without the fancy reactor changing the UCS. When you are actually editing the drawing and exit, you use the button "set UCS to World, Save, Close" and move to the next one. Just another thought. Glen Quote
chulse Posted April 14, 2010 Author Posted April 14, 2010 It looks like you are most of the way to where you want to be, but I just wanted to toss another option out there. I have a macro on a button in a toolbar: "Zoom Save Close". It zooms extents on both model and paper space, locks the viewports, saves the drawing and closes it. You could write one that would set the UCS to World. This way, you can still exit the drawing without the fancy reactor changing the UCS. When you are actually editing the drawing and exit, you use the button "set UCS to World, Save, Close" and move to the next one. Just another thought. Glen Good idea. However, I'd prefer not to leave this up to the user, but rather be completely "behind the scenes" and not rely on the user doing or remembering anything... Quote
chulse Posted April 15, 2010 Author Posted April 15, 2010 Ok, this is a shameless bump... but does anyone have any ideas how to automate the turning on/off of the reactor based on when the file was last saved? Quote
alanjt Posted April 15, 2010 Posted April 15, 2010 Ok, this is a shameless bump... but does anyone have any ideas how to automate the turning on/off of the reactor based on when the file was last saved? vl-file-systime(vl-file-systime filename) Arguments filename A string containing the name of the file to be checked. Return Values A list containing the modification date and time, or nil, if the file is not found. Determines the size of a file, in bytes Returns last modification time of the specified file 216 | AutoLISP Reference The list returned contains the following elements: n year n month n day-of-week n day-of-month n hours n minutes n seconds Note that Monday is day 1 of day-of-week, Tuesday is day 2, etc. Examples _$ (vl-file-systime "c:/program files/acad2000/sample/visuallisp/yinyang.lsp") (1998 4 3 8 10 6 52 0) The returned value shows that the file was last modified in 1998, in the 4th month of the year (April), the 3rd day of the week (Wednesday), on the 10th day of the month, at 6:52:0. ............... Quote
chulse Posted April 15, 2010 Author Posted April 15, 2010 alanjt - thanks How can I compare that value to the current time/date? Is the current date saved in a variable somewhere and would the list structure be the same? Quote
alanjt Posted April 16, 2010 Posted April 16, 2010 alanjt - thanksHow can I compare that value to the current time/date? Is the current date saved in a variable somewhere and would the list structure be the same? (getvar 'cdate) You'll have to do a little converting. Quote
chulse Posted April 17, 2010 Author Posted April 17, 2010 Thanks - this should keep me busy for a while. BTW, I decided to keep it turned off by default (at least until I can make the date thing work...) Quote
Lee Mac Posted April 17, 2010 Posted April 17, 2010 Be careful with vl-file-systime, if I remember, it doesn't report too well with files that are open. Quote
alanjt Posted April 17, 2010 Posted April 17, 2010 Be careful with vl-file-systime, if I remember, it doesn't report too well with files that are open. Didn't know that. Granted, I've never thought of using it on an open file. Quote
Lee Mac Posted April 17, 2010 Posted April 17, 2010 I'm not sure that this would be any more accurate: ;; Get File Last Modified time (Lee Mac) ;; Args: Filepath of file to query ;; Returns: Julian Date (defun GetLastModified ( file / fso fObj date ) (vl-load-com) (setq fso (vlax-create-object "Scripting.FileSystemObject")) (cond ( (zerop (vlax-invoke fso 'FileExists file))) ( (setq fObj (vlax-invoke-method fso 'GetFile file) date (+ 2415019 (vlax-get-property fObj 'DateLastModified))))) (vlax-release-object fso) date) (defun c:LastMod ( / f ) (if (setq f (getfiled "Select File to Query" "" "" 16)) (princ (strcat "\nLast Modified: " (toDate (rtos (GetLastModified f) 2 15) "DD.MO.YYYY HH:MM:SS")))) (princ)) (defun toDate ( str format ) (menucmd (strcat "m=$(edtime," str "," format ")"))) Quote
Lee Mac Posted April 17, 2010 Posted April 17, 2010 More fun with the FSO ;; Get File Information (Lee Mac) ;; Args: Filepath of file to query ;; Returns: (<Filename> <Created> <LastAccessed> <LastModified> <Size>) (defun GetFileInfo ( file ) (vl-load-com) (setq fso (vlax-create-object "Scripting.FileSystemObject")) (cond ( (zerop (vlax-invoke fso 'FileExists file))) ( (setq fObj (vlax-invoke-method fso 'GetFile file)) (setq info (mapcar (function (lambda ( property ) (vlax-get fObj property))) '(Name DateCreated DateLastAccessed DateLastModified Size))))) (vlax-release-object fso) info) (defun c:test ( / f Date Size i ) (setq Date (lambda ( d f ) (toDate (rtos (+ d 2415019) 2 15) f)) Size (lambda ( s f ) (rtos (/ s (float f)) 2 3))) (if (and (setq f (getfiled "Select File to Query" "" "" 16)) (setq i (GetFileInfo f))) (mapcar (function princ) (mapcar (function strcat) '("\nName: " "\nCreated: " "\nAccessed: " "\nModified: " "\nSize (KB): ") (mapcar (function (lambda ( foo property args ) (apply foo (cons property args)))) '(strcat Date Date Date Size) i '(nil ("DD.MO.YYYY HH:MM") ("DD.MO.YYYY HH:MM") ("DD.MO.YYYY HH:MM") (1024.)))))) (princ)) (defun toDate ( str format ) (menucmd (strcat "m=$(edtime," str "," format ")"))) Quote
chulse Posted April 19, 2010 Author Posted April 19, 2010 I'll need to play with these... Thanks! Quote
3dwannab Posted November 9 Posted November 9 (edited) On 4/14/2010 at 3:13 PM, alanjt said: DANGEROUS!!! This is something I would recommend you have to turn on. In Maxscript there's a function to check if the file is dirty, i.e. not saved with: checkForSave() Is there something similar for VLISP? I was planning on using the reactor Lee had written, but I would need this check to implement it; as you say, it's dangerous. Something like this at the end of the function: (initget "Yes No") (if (and (not (3d_CheckSavedStatus)) ;; Use fn below (eq (getkword "\nAre you sure you want to save the file? [Yes/No] <No>: ") "Yes") ) (progn (if (not (eq "" (vla-get-FullName doc))) (vla-saveas doc (vla-get-FullName doc)) ) ) ) Edited November 9 by 3dwannab updated to reference fn below Quote
3dwannab Posted November 9 Posted November 9 (edited) Here's a roll your own: ;; 3d_CheckSavedStatus ;; Returns T if the file has been saved ;; Written on 2024.11.09 by 3dwannab (defun 3d_CheckSavedStatus (/ doc) (vl-load-com) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object))) (= :vlax-true (vla-get-Saved doc)) ) Edited November 9 by 3dwannab Quote
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.