Author Topic: Update the drawing list only if necessary  (Read 1942 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Update the drawing list only if necessary
« on: March 21, 2018, 04:49:55 PM »
Scenario:
1) DwgFolder folder containing dwg1 dwg2 dwg3, the most recent file has the date: 03/21/2018 12:00

2) I create a list of drawings on file DwgList.csv (or, xls, txt, ...) this file has the creation date for example 03/21/2018 16:30
   in this list will be written some titlte-block data
   
3) in the folder DwgFolder 2 new files are added (dwg4 dwg5) with date 03/22/2018 08:20
   and the file dwg2 is modified and has the date 03/22/2018 08:45

Question: what is the best/fast way to get the list only of modified or added files (after 03/21/2018 16:30): dwg4 dwg5 dwg2
in order to update the drawing list processing only the modified or added drawings?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Update the drawing list only if necessary
« Reply #1 on: March 21, 2018, 04:59:32 PM »
Get the 'vl-file-systime' of the files, translate to the CDATE format and compare.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Update the drawing list only if necessary
« Reply #2 on: March 21, 2018, 05:15:32 PM »
Note that vl-file-systime is unreliable: returns nil if the drawing is open.

Work-rounds abound, including mine, cheers.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Update the drawing list only if necessary
« Reply #3 on: March 22, 2018, 04:29:09 AM »
Grazie Roy and Michael,

>> Work-rounds abound, including mine, ...

It seems to me that this is exactly what I was looking for.
 :yes: :-)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Update the drawing list only if necessary
« Reply #4 on: March 22, 2018, 06:12:44 AM »
Based on your suggestions I wrote this:
Code: [Select]
(defun ALE_Files_ModifiedAfter (FulNam FilNms / FilPat FilLst OutLst SFsObj RefDat)
  (if (findfile FulNam)
    (progn
      (setq
        SFsObj (vlax-create-object "scripting.filesystemobject")
        FilLst (vl-directory-files (vl-filename-directory FulNam) FilNms 1)
        FilPat (strcat (vl-filename-directory FulNam) "\\")
        RefDat (ALE_Files_SysTime SFsObj FulNam)
      )
      (foreach ForElm FilLst
        (and (> (ALE_Files_SysTime SFsObj (strcat FilPat ForElm)) RefDat) (setq OutLst (cons ForElm OutLst)))
      )
      (vlax-release-object SFsObj)
      (if OutLst (cons FilPat OutLst))
    )
  )
)
Code: [Select]
; based on Lee Mac code
(defun ALE_Files_SysTime (SFsObj FulNam / FilDat FilObj)
  (if (findfile FulNam)
    (progn
      (setq FilDat
        (vl-catch-all-apply
          (function
            (lambda ( )
              (setq FilObj (vlax-invoke-method SFsObj 'getfile FulNam))
              (+ 2415019 (vlax-get-property FilObj 'datelastmodified))
            )
          )
        )
      )
      (and (= 'vla-object (type FilObj)) (vlax-release-object FilObj))
      (if (vl-catch-all-error-p FilDat)
        (progn (prompt (vl-catch-all-error-message FilDat)) nil)
        FilDat
      )
    )
  )
)

Comando: (ALE_Files_ModifiedAfter "Z:\\Temp\\pippo.txt" "*.DWG")
("Z:\\Temp\\" "0242C.dwg" "0242C-002.dwg" "0242C-001.dwg")

Any suggestion is appreciated.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Update the drawing list only if necessary
« Reply #5 on: March 22, 2018, 07:20:25 AM »
Note that vl-file-systime is unreliable: returns nil if the drawing is open.
FYI: This problem does not exist in BricsCAD.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Update the drawing list only if necessary
« Reply #6 on: March 22, 2018, 08:07:48 AM »
That doesn’t surprise me.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Update the drawing list only if necessary
« Reply #7 on: March 22, 2018, 08:12:59 AM »
Glad you appear to have a solution Marc (I’m on my phone so cant test).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.com • http://cadanalyst.slack.com • http://linkedin.com/in/cadanalyst

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Update the drawing list only if necessary
« Reply #8 on: March 22, 2018, 11:10:08 AM »
New version:
Code: [Select]
; Function: ALE_Files_ModifiedAfter
;
; Version 1.01 - 2018/03/22
;
; Arguments:
;
; a) date & path&filespec
; InfRef = real   (Julian Date)
; FilNms = string (path&filespec)
; Return:  list (<path of FilNms> <all file names modified or added after InfRef date>)
;
; b) ref-file & filespec
; InfRef = string (fullname)   
; FilNms = string (filespec)
; Return:  list (<path of InfRef> <all file names modified or added after date of InfRef file>)
;
;
; Examples:
; a) (ALE_Files_ModifiedAfter (getvar "DATE") "Z:\\Temp\\*.DWG")
; b) (ALE_Files_ModifiedAfter "Z:\\Temp\\Foo.txt" "*.DWG")
;
;
(defun ALE_Files_ModifiedAfter (InfRef FilNms / FilPat FilLst OutLst SFsObj)
  (setq SFsObj (vlax-create-object "scripting.filesystemobject"))
  (if (numberp InfRef)
    (setq
      FilPat (strcat (vl-filename-directory FilNms) "\\")
      FilLst (vl-directory-files FilPat (strcat (vl-filename-base FilNms) (vl-filename-extension FilNms)) 1)
    )
    (if (findfile InfRef)
      (setq
        FilPat (strcat (vl-filename-directory InfRef) "\\")
        FilLst (vl-directory-files FilPat FilNms 1)
        InfRef (ALE_Files_SysTime SFsObj InfRef)
      )
    )
  )
  (foreach ForElm FilLst
    (and (> (ALE_Files_SysTime SFsObj (strcat FilPat ForElm)) InfRef) (setq OutLst (cons ForElm OutLst)))
  )
  (vlax-release-object SFsObj)
  (if OutLst (cons FilPat OutLst))
)