Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18

Thread: time and date sorting and filtering

  1. #11
    Active Member
    Join Date
    2012-11
    Posts
    98

    Default Re: time and date sorting and filtering

    Quote Originally Posted by pbejse View Post
    This...



    Writing a foolproof program requires a lot of support from the users themselves and of course the IT department.



    You dont really need to "save" the drawing back and forth from one folder to another, just use VL-FILE-COPY function.

    Now as for"it will not back up." , what you can do is write a support routine that will retrieve datas of file in question e.g. username and an alert will flash on the screen " file currently in use by user blah blah " then do what you must

    HTH
    Cheers for the "vl-file-copy" function, that will make things work far more smoothly!
    also i dont believe overwriting will be an issue as all i want the lisp to do it search the folder and if another file is found, then read its date and if it has been saved within 3 hours of the the current date then dont save else write a new file with the current date in the name.
    I want a directy with a list of backups.
    i dont want there to be any overwriting.

  2. #12
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,344

    Default Re: time and date sorting and filtering

    Well then try this:
    Code:
    (defun ISOTime->CDate  (source)
      (apply '+
             (mapcar '*
                     (read (strcat "(" (vl-string-translate ".-:" "   " str) ")"))
                     '(10000.0 100.0 1.0 0.01 0.0001))))
    
    (defun CDate->ISOTime  (dt)
      (apply 'strcat
             (mapcar '(lambda (item)
                        (cond ((wcmatch item "~#*") item)
                              ((< (strlen item) 2) (strcat "0" item))
                              (t item)))
                     (list (itoa (fix (/ dt 10000)))
                           "-"
                           (itoa (fix (/ (rem dt 10000) 100)))
                           "-"
                           (itoa (fix (rem dt 100)))
                           " "
                           (itoa (fix (* (rem dt 1) 100)))
                           ":"
                           (itoa (fix (* (rem dt 0.01) 10000)))
                           ":"
                           (itoa (fix (* (rem dt 0.0001) 1000000)))))))
    
    
    (defun DoBackup  (/ lastBak path dwgname)
      (vl-load-com)
      ;; Find last backup of current file
      (setq lastBak
             (last
               (vl-sort
                 (mapcar '(lambda (filename)
                            (cons (strcat path filename)
                                  (ISOTime->CDate (substr filename (- (strlen filename) 22) 19))))
                         (vl-directory-files
                           (setq path (strcat (getvar 'DwgPrefix) "\\Backup\\"))
                           (strcat (setq dwgname (vl-filename-base (getvar 'DwgName))) "*.DWG")
                           1))
                 '(lambda (a b) (< (cdr a) (cdr b))))))
      (if (or (not lastBak) ;Check if there isn't yet a backup
              (> (getvar 'CDate) (+ (cdr lastBak) 0.03))) ;Check for 3 hours interval
        (progn (vl-mkdir path) ;Ensure the backup folder exists
               (command "_.QSAVE")
               (vl-file-copy (strcat (getvar 'DwgPrefix) (getvar 'DwgName))
                             (strcat path
                                     filename
                                     " "
                                     (vl-string-translate ":" "." (CDate->ISOTime (getvar 'CDate)))
                                     ".DWG")))))
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  3. #13
    Active Member
    Join Date
    2012-11
    Posts
    98

    Default Re: time and date sorting and filtering

    Hey mate.
    Sorry to be a bother but this doesnt appear to be working and everything to do with the time handling is way out of my league.
    Ive tried tweaking a few parts where i thought it might be breaking but still, no go.
    Is this lisp right to run straight away or should i be adding this to my own lisp?

    Cheers

  4. #14
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,344

    Default Re: time and date sorting and filtering

    You'll probably want to add it to your own. Basically you'd just be calling the DoBackup function. The other 2 are just helper functions to convert between an ISO Date-Time string and the CDate real value.

    To explain the time conversion from ISo to CDate:
    1. Translate each non numeric into a space.
    2. Read the result in as a list of numbers
    3. Multiply each number by a constant to "move" it into the correct position in the real value
    4. Add all these results together


    To convert from CDate to ISO:
    1. You use fix to remove the fractional part from a real value
    2. Divide / Multiply to move the orthing of the CDate to be at the integer portion of the real.
    3. Trim off anything above the portion using rem (Remainder).
    4. Convert each integer (itoa)
    5. If number & length is less than 2 add a 0 prefix.
    6. Finally strcat all of this together
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  5. #15
    Active Member
    Join Date
    2012-11
    Posts
    98

    Default Re: time and date sorting and filtering

    Hey all

    Ive read through all of the code you guys have thrown up and have tried to alter it to suit my needs.
    unfortunately ive hit a wall and i cant seem to overcome it.
    any help troubleshooting this would be greatly appreciated.
    the problem seems to be around the last lines of the FILTER.
    the general idea of what this is supposed to do is:

    IF new year is > old year
    THEN run program
    IF new year is = old year
    THEN IF new month is > old month
    THEN run program
    IF new month is = old month
    THEN IF new day is > old day
    THEN run program
    IF new day is = old day
    etc...


    (defun C:MMBackup (/)
    (setq dwgpath (getvar "dwgprefix")
    dwgname (getvar "dwgname")
    date (menucmd "M=$(edtime,$(getvar,date),YYYY.MO.DD-HH:MM am/pm)")
    year (substr date 1 4)
    month (substr date 6 2)
    day (substr date 9 2)
    hour (substr date 12 2)
    minute (substr date 15 2)
    AM/PM (substr date 18 2)
    temp1 "M13536-M-L06-101{2014.01.29_16-10}.dwg"
    )

    (if (= (atoi (substr date 12 2)) 12)
    (cond ((= am/pm "am") (setq AM/PM "pm"))
    ((= am/pm "pm") (setq AM/PM "am"))
    )
    )


    (setq hour (if (= (substr date 18 2) "pm")
    (itoa (+ (atoi (substr date 12 2)) 12))
    (atoi (substr date 12 2))
    )
    )

    (setq date (strcat year "." month "." day "_" hour "-" minute))

    ;;;;;;;;;;;;;;
    ;;;;FILTER;;;;
    ;;;;;;;;;;;;;;
    (cond
    (
    (> (atoi year) (atoi (substr temp1 (+ 2 (vl-string-search "{" temp1)) 4)))
    (setq test "Run1")
    )

    (
    (= (atoi year) (atoi (substr temp1 (+ 2 (vl-string-search "{" temp1)) 4)))
    (cond
    (
    (> (atoi month) (atoi (substr temp1 (+ 7 (vl-string-search "{" temp1)) 2)))
    (setq test "Run2")
    )

    (
    (= (atoi month) (atoi (substr temp1 (+ 7 (vl-string-search "{" temp1)) 2)))
    (cond
    (
    (> (atoi day) (atoi (substr temp1 (+ 10 (vl-string-search "{" temp1)) 2)))
    (setq test "Run3")
    )

    (
    (= (atoi day) (atoi (substr temp1 (+ 10 (vl-string-search "{" temp1)) 2)))
    (cond
    (
    (> (- (atoi hour) 3) (atoi (substr temp1 (+ 13 (vl-string-search "{" temp1)) 2)))
    (setq test "Run4")
    )

    (
    (= (- (atoi hour) 3) (atoi (substr temp1 (+ 13 (vl-string-search "{" temp1)) 2)))
    (cond
    (
    (>= (atoi minute) (atoi (substr temp1 (+ 16 (vl-string-search "{" temp1)) 2)))
    (setq test "Run5")
    )

    (
    (< (atoi minute) (atoi (substr temp1 (+ 16 (vl-string-search "{" temp1)) 2)))
    (setq test "Error6")
    )
    (setq test "error5")
    )
    )
    (setq test "error4")
    )
    )
    (setq test "error3")
    )
    )
    (setq test "error2")
    )
    )
    (setq test "error1")
    )

    ;;;;;;;;;;;;;;
    ;;;;FILTER;;;;
    ;;;;;;;;;;;;;;


    princ test

    )
    (c:mmbackup)

  6. #16
    Certifiable AUGI Addict irneb's Avatar
    Join Date
    2007-07
    Location
    Jo'burg SA
    Posts
    4,344

    Default Re: time and date sorting and filtering

    You don't need to go through all that. The nice thing about the way CDate stores it is you only need one comparison. E.g. a date is stored as one single floating point value YYYYMMDD.HHIISS. Which in turn means comparing equality takes account of all the portions of the date/time in one go:
    Code:
    (defun RunCode () (princ "Run My Code"))
    (if (> newDate oldDate)
      (RunCode)
    )
    Would be equivalent to something like this:
    Code:
    (if (> (fix (/ newDate 10000)) (fix (/ oldDate 10000))) ;Check Year
      (RunCode)
      (if (> (rem (/ newDate 100) 100) (rem (/ oldDate 100) 100)) ;Check Month
        (RunCode)
        (if (> (rem newDate 100) (rem oldDate 100)) ;Check Day
          (RunCode)
          (if (> (rem (* newDate 100) 100) (rem (* oldDate 100) 100)) ;Check Hour
            (RunCode)
            (if (> (rem (* newDate 10000) 100) (rem (* oldDate 10000) 100)) ;Check Minute
              (RunCode)
              (if (> (rem (* newDate 1000000) 100) (rem (* oldDate 1000000) 100)) ;Check Second
                (RunCode)))))))
    Knowledge is proportional to experience, but wisdom is inversely proportional to ego!
    My little bit of "wisdom": Hind-sight is useless, unless used to improve the next forethought!

  7. #17
    Active Member
    Join Date
    2012-11
    Posts
    98

    Default Re: time and date sorting and filtering

    awesome, I think I see what you are getting at now.
    Ill give it another crack and see what i can do.
    your way looks heaps easier!

    Cheers mate

  8. #18
    I could stop if I wanted to pbejse's Avatar
    Join Date
    2010-10
    Posts
    395

    Default Re: time and date sorting and filtering

    Dont use solely the filename for date information. Yes you determine the "valid" last backup via "date" on the filename but use the info from
    vl-file-systime or similar function for date comparison.

    My 2 cents.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Date/Time Label
    By sfassnacht in forum Revit Architecture - General
    Replies: 8
    Last Post: 2010-11-03, 06:15 PM
  2. Time & Date Format
    By d.stairmand in forum Revit - Platform
    Replies: 5
    Last Post: 2008-07-23, 05:54 PM
  3. Is it possible to have just a date stamp? i.e. no time
    By david.kingham in forum Revit Architecture - General
    Replies: 5
    Last Post: 2006-05-19, 06:00 AM
  4. Replies: 2
    Last Post: 2005-12-06, 12:36 PM
  5. Date/Time stamp
    By terrypaul1 in forum AutoCAD Customization
    Replies: 2
    Last Post: 2005-07-07, 08:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •