Compare modified date of open dwg to other files?

Discussion in 'AutoCAD' started by Rusty Gesner, Sep 29, 2004.

  1. Rusty Gesner

    Rusty Gesner Guest

    I need to programmatically compare the last modified file date/time of
    an open drawing with that of other drawing files. This is the
    "Modified:" date/time shown if you right-click on a file in Windows and
    choose properties or in AutoCAD by choosing File, Drawing Properties,
    General.. You can programmatically obtain this for files which are not
    open by using the vl-file-systime function, but vl-file-systime returns
    nil for the currently open file. This not the same date/time as the
    Created and Modified dates shown in the Statistics tab of the Drawing
    Properties, which can be accessed with the TDCREATE and TDUPDATE
    sysvars. Although you can access the Custom tab data of the Drawing
    Properties in the object model, you apparently can't access the
    General tab's data.

    Any ideas?

    Thanks - Rusty
     
    Rusty Gesner, Sep 29, 2004
    #1
  2. Rusty - you can use the FileSystemObject to return file properties; here is what I have:


    ;;;;;f:file_data uses the file system object to return information about a file

    ;;e.g.: (f:file_data (strcat (getvar "DWGPREFIX")(getvar "DWGNAME")))

    (defun f:file_data (pth / fso fil ret)
    (if
    (and
    (findfile pth)
    (setq fso (f:vlerr 'vla-GetInterfaceObject (list (vlax-get-acad-object) "Scripting.FileSystemObject") nil))
    (setq fil (f:vlerr 'vlax-invoke-method (list fso 'GetFile pth) nil))
    );and
    (setq ret (mapcar (function (lambda (at)
    (cons (vl-symbol-name at) (f:variant_value (f:vlerr 'vlax-get-property (list fil at) nil)))
    ));function
    (list 'Attributes 'DateCreated 'DateLastAccessed 'DateLastModified
    'Name 'Path 'ShortName 'ShortPath 'Size 'Type)
    );mapcar
    );setq
    )
    (f:vl-release (list fso fil))
    ret)

    ;;f:variant_value: force any value from a variant
    (defun f:variant_value (val)
    (if (= (type val) 'variant)
    (vlax-variant-value val)
    val
    )
    )

    ;;f:vlerr simplified error catching routine for vl-catch*
    ;;f:vlerr usage (setq en (f:vlerr 'vla-get-Area (list en) nil))
    ;;f:vlerr tag = true for debugging: princes error message


    (defun f:vlerr (fun lst tag / ret *error*)

    (if (or (null lst) (not (listp lst)))
    (progn
    (f:prm (list "\n***f:vlerr error: lst variable must be passed as a list (" lst ").***"))
    (exit)
    )
    )


    (if (vl-catch-all-error-p (setq ret (vl-catch-all-apply fun lst)))
    (if tag
    (progn (f:prm (list "\n" (vl-catch-all-error-message ret) "\n" fun lst)) nil)
    nil
    )
    (if (not ret) (setq ret T) ret)
    )
    (if (= (type ret) 'VL-CATCH-ALL-APPLY-ERROR) (setq ret nil))


    ret)

    (defun f:vl-release (lst)
    (if (listp lst)
    (mapcar '(lambda (x) (f:vlerr 'vlax-release-object (list x) nil)) lst)
    (f:vlerr 'vlax-release-object (list lst) nil)
    )
    )

    Peter
     
    petersciganek, Sep 29, 2004
    #2
  3. Rusty Gesner

    Rusty Gesner Guest

    Peter,

    That's so close, but the date returned isn't quite precise enough and I
    don't see any way to control its precision. For example, for a file
    saved this evening, it returns 38259.9 for DATELASTMODIFIED. I'm
    guessing that is the number of days since 1900, but with only a 0.1 day
    of precision, I can't reliably distinguish which file is most recent.

    Any ideas?

    Thanks - Rusty
     
    Rusty Gesner, Sep 30, 2004
    #3
  4. Rusty,

    The value is more precise than 1 decimal point - try (rtos value 2 8) or compare by subtraction.

    Peter
     
    petersciganek, Sep 30, 2004
    #4
  5. Rusty Gesner

    Rusty Gesner Guest

    Peter, that works great now, thanks.

    Would you happen to have code that writes the DateLastModified to a file?

    Thanks - Rusty
     
    Rusty Gesner, Oct 3, 2004
    #5
  6. Use open and write-line functions - here's my standard function:

    ;;f:write_lst [string or list of strings] [filename] [how ("a" "w")]

    (defun f:write_lst (lst fil how / fp)
    (cond
    ((not (setq fp (open fil how))) nil)
    (T
    (if (not (listp lst))
    (setq lst (list lst))
    )
    (mapcar '(lambda (tx) (write-line tx fp)) lst)
    (close fp)
    fil
    )
    )
    )

    Peter
     
    petersciganek, Oct 4, 2004
    #6
  7. Rusty Gesner

    Rusty Gesner Guest

    Sorry, that's not what I meant.

    I need to plug arbitrary dates into the DateLastModified of a drawing
    files' FileSystemObjects (without otherwise modifying dwg files or
    resetting the system clock). Kinda like your f:file_data program, but
    writing the file attributes instead of reading them.

    Thank - Rusty
     
    Rusty Gesner, Oct 5, 2004
    #7
  8. Rusty Gesner

    Dean Guest

    If using doslib is an option, I'm pretty sure the dos_touch function will do
    this.

     
    Dean, Oct 5, 2004
    #8
  9. petersciganek, Oct 5, 2004
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.