Author Topic: Batch operations on multiple files  (Read 10415 times)

0 Members and 1 Guest are viewing this topic.

Dave M

  • Newt
  • Posts: 196
Batch operations on multiple files
« on: February 26, 2020, 04:49:33 PM »
I have a plans that I plot in B/W.  I also plot these plans with certain layers that plot in color.  The way I have done it in the past was to create a script file that turned those layers on and then plotted the file and closed without saving.  I would use the Scriptpro program to do this on multiple files.  Sometimes I would set it up to run over night.


I am looking for a replacement to Scriptpro and was considering JTB Smartbatch as an alternative.  Does anyone have experience with this program?


Looking for suggestions


thanks
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox

notredave

  • Newt
  • Posts: 140
Re: Batch operations on multiple files
« Reply #1 on: March 10, 2020, 06:28:36 AM »
Lee Mac has a script writer program here: I use it all the time. It's wonderful.

http://www.lee-mac.com/scriptwriter.html

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Batch operations on multiple files
« Reply #2 on: March 10, 2020, 03:40:22 PM »
A very long time ago I wrote my self a "script running lisp" that essentially just runs all lisp, bat and exe files found in a certain directory. I created an AutoCAD profile (stripped down of all unnecessary stuff) that just loaded that lisp so when I wanted to run a script on a series of drawings I just opened that AutoCAD profile and choose the files I wanted to run the scripts on. Simple and effective.

Recently I was asked to write a program (C++) to dig into 1,000's of folders to find specific files. My program generated a script (lisp) for each file and then created a "master-run-all.bat" with those files to run a script on. The final tally of drawings was 5,000 and it took a weekend to process all those drawings, I was told. ...that was very specific and not generic at all but I offered up the concept just because it was sort of related.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Crank

  • Water Moccasin
  • Posts: 1503
Re: Batch operations on multiple files
« Reply #3 on: March 10, 2020, 03:48:21 PM »
If you're looking for speed, try the AcCoreConsole.
Vault Professional 2023     +     AEC Collection

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Batch operations on multiple files
« Reply #4 on: March 11, 2020, 08:11:48 AM »
If you're looking for speed, try the AcCoreConsole.

One point I'll recommend, is running each drawing in its own core console session rather than processing all drawings in one session.  The latter is fine for small numbers of files but arbitrarily large collections will lead to errors as memory is not fully released.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

darktom

  • Mosquito
  • Posts: 1
Re: Batch operations on multiple files
« Reply #5 on: March 13, 2020, 04:37:42 AM »
If you're looking for speed, try the AcCoreConsole.
Also recommend

paulslondon

  • Mosquito
  • Posts: 1
Re: Batch operations on multiple files
« Reply #6 on: March 13, 2020, 05:32:21 AM »
Thanks for help

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Batch operations on multiple files
« Reply #7 on: April 14, 2020, 11:24:36 AM »
I needed to do some batch processing of drawings today. I had never heard of "accoreconsole" (I got out of AutoCAD before it came about) but I followed the above link and I created a quick solution for myself this morning.

I created a batch script I can drag drawing files to to run a script on. The script file to run and the batch script are located in the same folder. Replace/fix the path as required (I only had AutoCAD 2018 installed on my laptop).

Batch Script: "BatchDrawings_accoreconsole.cmd"
Code - Bash: [Select]
  1. @echo off
  2. :: process files given as argument to this batch script.
  3. ::
  4. :: Last Updated: 04.14.20 9:41:00 AM
  5. ::
  6. :: BY: John Kaul
  7.  
  8. set script="%~dp0\BatchDrawings_accoreconsole.scr"
  9. set script=%script:\\=\%
  10. :processArgs
  11.         if [%1]==[] goto endmark
  12.         call "C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe" /i "%~f1" /s %script% /l en-US
  13.         if errorlevel 1 goto errormark
  14.         SHIFT
  15.         goto processArgs
  16. :errormark
  17.         echo.
  18.         echo.
  19.         echo ERROR processing %~f1
  20.         pause
  21.         echo.
  22. :endmark
  23. rem
  24. rem     finished
  25. rem

Sample script: "BatchDrawings_accoreconsole.scr"
(Sample only, replace with what you want)
Code - Auto/Visual Lisp: [Select]
  1. ( (lambda ( / *error* ERROR-LST- )
  2.  
  3.        (setq
  4.          ERROR-LST-
  5.                     '("AUTOSNAP" "OSMODE" "APERTURE" "HPSPACE" "HPASSOC"
  6.                       "MIRRTEXT" "AUPREC" "LUPREC" "DIMZIN" "CECOLOR" "CLAYER"
  7.                       "CMDECHO" "FILEDIA" "OSMODE")
  8.          ERROR-LST- (mapcar (function (lambda (a) (list 'setvar a (getvar a)))) ERROR-LST-)
  9.        );_end setq
  10.  
  11.        (defun *error* (msg)
  12.           (command) (command)
  13.           (mapcar 'eval ERROR-LST-))
  14.  
  15.     (mapcar
  16.       '(lambda ( x / )
  17.          (eval x)
  18.          (repeat 2 (command))
  19.          (princ))
  20.       '(
  21.         ;; --== ==--
  22.         ;;
  23.  
  24.  
  25.         ;;
  26.         ;; --== ==--
  27.         (command "audit" "yes")
  28.         ;; audit the drawing
  29.         (command "bldsyspurge")
  30.         (repeat 5 (command "_purge" "a" "*" "n"))
  31.         ;; purge the drawing a ;few times
  32.         (*error* "")
  33.         (command "_qsave")
  34.         ;; save
  35.         )
  36.       ) ; mapcar
  37.     (princ)
  38.     )
  39.  )
  40.  

Drag and drop the drawing files to the "BatchDrawings_accoreconsole.cmd" you want to process.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Dave M

  • Newt
  • Posts: 196
Re: Batch operations on multiple files
« Reply #8 on: April 15, 2020, 08:46:13 PM »
Thanks for sharing with me.  I will give it a go!
Civil 3D 2018 - Microstation SS4 - Windows 10 - Dropbox

framednlv

  • Newt
  • Posts: 64
Re: Batch operations on multiple files
« Reply #9 on: April 16, 2020, 10:05:33 AM »
I needed to do some batch processing of drawings today. I had never heard of "accoreconsole" (I got out of AutoCAD before it came about) but I followed the above link and I created a quick solution for myself this morning.

I created a batch script I can drag drawing files to to run a script on. The script file to run and the batch script are located in the same folder. Replace/fix the path as required (I only had AutoCAD 2018 installed on my laptop).

Batch Script: "BatchDrawings_accoreconsole.cmd"
Code - Bash: [Select]
  1. @echo off
  2. :: process files given as argument to this batch script.
  3. ::
  4. :: Last Updated: 04.14.20 9:41:00 AM
  5. ::
  6. :: BY: John Kaul
  7.  
  8. set script="%~dp0\BatchDrawings_accoreconsole.scr"
  9. set script=%script:\\=\%
  10. :processArgs
  11.         if [%1]==[] goto endmark
  12.         call "C:\Program Files\Autodesk\AutoCAD 2018\accoreconsole.exe" /i "%~f1" /s %script% /l en-US
  13.         if errorlevel 1 goto errormark
  14.         SHIFT
  15.         goto processArgs
  16. :errormark
  17.         echo.
  18.         echo.
  19.         echo ERROR processing %~f1
  20.         pause
  21.         echo.
  22. :endmark
  23. rem
  24. rem     finished
  25. rem

Sample script: "BatchDrawings_accoreconsole.scr"
(Sample only, replace with what you want)
Code - Auto/Visual Lisp: [Select]
  1. ( (lambda ( / *error* ERROR-LST- )
  2.  
  3.        (setq
  4.          ERROR-LST-
  5.                     '("AUTOSNAP" "OSMODE" "APERTURE" "HPSPACE" "HPASSOC"
  6.                       "MIRRTEXT" "AUPREC" "LUPREC" "DIMZIN" "CECOLOR" "CLAYER"
  7.                       "CMDECHO" "FILEDIA" "OSMODE")
  8.          ERROR-LST- (mapcar (function (lambda (a) (list 'setvar a (getvar a)))) ERROR-LST-)
  9.        );_end setq
  10.  
  11.        (defun *error* (msg)
  12.           (command) (command)
  13.           (mapcar 'eval ERROR-LST-))
  14.  
  15.     (mapcar
  16.       '(lambda ( x / )
  17.          (eval x)
  18.          (repeat 2 (command))
  19.          (princ))
  20.       '(
  21.         ;; --== ==--
  22.         ;;
  23.  
  24.  
  25.         ;;
  26.         ;; --== ==--
  27.         (command "audit" "yes")
  28.         ;; audit the drawing
  29.         (command "bldsyspurge")
  30.         (repeat 5 (command "_purge" "a" "*" "n"))
  31.         ;; purge the drawing a ;few times
  32.         (*error* "")
  33.         (command "_qsave")
  34.         ;; save
  35.         )
  36.       ) ; mapcar
  37.     (princ)
  38.     )
  39.  )
  40.  

Drag and drop the drawing files to the "BatchDrawings_accoreconsole.cmd" you want to process.
This works great.
I created a PDF plotting script and setup a shortcut in windows SendTo menu.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Batch operations on multiple files
« Reply #10 on: April 16, 2020, 10:19:10 AM »
This works great.
I created a PDF plotting script and setup a shortcut in windows SendTo menu.
Thanks! Yes it does; I just scripted a 100 or so drawings this morning.
Nice idea about the SendTo menu.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

framednlv

  • Newt
  • Posts: 64
Re: Batch operations on multiple files
« Reply #11 on: April 16, 2020, 10:23:10 AM »
The batch name I use is different but this is in a setup.bat file:
Code: [Select]
copy "BatchDrawings_accoreconsole.cmd - Shortcut.lnk" "C:\Users\%username%\AppData\Roaming\Microsoft\Windows\SendTo"
PDF routine to plot to desktop\PDFs folder:
Code: [Select]
(COMMAND "TILEMODE" "0")
(command "PSPACE")
(command "zoom" "e")
(command "zoom" "e" "regenall")
(setq extents (mapcar '- (getvar 'extmax) (getvar 'extmin))maxdim (apply 'max extents))
(setq maxdim (distance (list (car (getvar "extmin")) 0.0 0.0)
(list (car (getvar "extmax")) 0.0 0.0)))
(cond
((>= maxdim 47)
(setq myps (strcat "ARCH full bleed E "(chr 40) "36.00 x 48.00 Inches" (chr 41) "")))
((>= maxdim 40)
(setq myps (strcat "ARCH full bleed E1 "(chr 40)"30.00 x 42.00 Inches"(chr 41)"")))
((>= maxdim 34.5)
(setq myps (strcat "ARCH full bleed D "(chr 40)"36.00 x 24.00 Inches"(chr 41)"")))
((>= maxdim 32)
(setq myps (strcat "ANSI full bleed D " (chr 40) "22.00 x 34.00 Inches" (chr 41) "")))
((>= maxdim 11.5)
(setq myps (strcat "ANSI full bleed B " (chr 40) "11.00 x 17.00 Inches" (chr 41) "")))
((<= maxdim 11.49)
(setq myps (strcat "ANSI full bleed A " (chr 40) "8.50 x 11.00 Inches" (chr 41) ""))))
(setq LL (getvar 'extmin) UR (getvar 'extmax) )
(if (> (- (car UR) (car LL)) (- (cadr UR) (cadr LL)))
(setq myoren "landscape")
(setq myoren "portrait"))
(if (= myoren "portrait")
(progn
(setq extents (mapcar '- (getvar 'extmax) (getvar 'extmin)) maxdim  (apply 'max extents))
(setq maxdim (distance (list (car (getvar "extmin")) 0.0 0.0)
(list (car (getvar "extmax")) 0.0 0.0)))
(cond
((> maxdim 10)
(setq myps (strcat "ANSI full bleed B "(chr 40)"11.00 x 17.00 Inches"(chr 41)""))))))
(acet-file-mkdir (strcat (getenv "UserProfile") "\\Desktop\\PDFs\\"))
-PLOT
y

DWG To PDF.pc3
(setq x myps)
Inches
(setq x myoren)
No
Extents
1:1
Center
Yes:
acad.ctb
Yes
Yes
No
No
(strcat (getenv "UserProfile") "\\Desktop\\PDFs\\" (cadr (fnsplitl (getvar 'dwgname))))
y
y



JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Batch operations on multiple files
« Reply #12 on: April 16, 2020, 10:56:48 AM »
Nice.

Thought (for future maintenance): You could add some documentation the options in the PLOT command in your script.
Code - Auto/Visual Lisp: [Select]
  1. ...
  2.         (command
  3.                 "-plot"
  4.                 "yes"                   ; Detailed plot configuration? [Yes/No] <No>:
  5.                 (getvar 'CTAB)          ; Enter a layout name or [?] <current tab>:
  6.                 "Ghostscript.pc3"       ; Enter an output device name or [?] <Ghostscript.pc3>:
  7.                 "ARCH E1 (30x42)"       ; Enter paper size or [?] <ARCH E1 (30x42)>:
  8.                 "inches"                ; Enter paper units [Inches/Millimeters] <Inches>:
  9.                 "landscape"             ; Enter drawing orientation [Portrait/Landscape] <Landscape>:
  10.                 "no"                    ; Plot upside down? [Yes/No] <No>:
  11.                 "limits"                ; Enter plot area [Display/Extents/Limits/View/Window] <Extents>:
  12.                 "1:1"                   ; Enter plot scale (Plotted Inches=Drawing Units) or [Fit] <1:1>:
  13.                 "center"                ; Enter plot offset (x,y) or [Center] <Center>:
  14.                 "yes"                   ; Plot with plot styles? [Yes/No] <Yes>:
  15.                 "Ghostscript.ctb"       ; Enter plot style table name or [?] (enter . for none) <Ghostscript.ctb>:
  16.                 "yes"                   ; Plot with lineweights? [Yes/No] <Yes>:
  17.                 "no"                    ; Scale lineweights with plot scale? [Yes/No] <No>:
  18.                 "no"                    ; Plot paper space first? [Yes/No] <No>:
  19.                 "no"                    ; Hide paperspace objects? [Yes/No] <No>:
  20.                 "yes"                   ; Write the plot to a file [Yes/No] <Y>:
  21.                 (strcat
  22.                         "C:\\<SOME>\\<LOCATION>\\"
  23.                         (vl-filename-base
  24.                              (getvar "dwgname"))
  25. ;;                             "-FULL-SIZE.plt"
  26.                              )          ; FILE NAME
  27.                 "yes"                   ; Save changes to page setup [Yes/No]? <N>
  28.                 "yes"                   ; Proceed with plot [Yes/No] <Y>:
  29.                 )
  30. ...
  31.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

framednlv

  • Newt
  • Posts: 64
Re: Batch operations on multiple files
« Reply #13 on: September 24, 2020, 07:47:16 PM »
Code: [Select]
@echo off
:: process files given as argument to this batch script.
::
:: Last Updated: 04.14.20 9:41:00 AM
::
:: BY: John Kaul
:: 
 
set script="LEFT BLANK"
set script=%script:\\=\%
:processArgs
        if [%1]==[] goto endmark
[color=red]title "%~f1"[/color]
        call "C:\Program Files\Autodesk\AutoCAD 2021\accoreconsole.exe" /i "%~f1" /s %script% /l en-US >"C:\temp\cleanup.log"
        if errorlevel 1 goto errormark
        SHIFT
        goto processArgs
:errormark
        echo.
        echo.
        echo ERROR processing %~f1
        pause
        echo.
:endmark
rem
rem     finished
rem
I added the red part above so it shows what file it is processing.
Is there any what to show what current number is, like 21 of 100?

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Batch operations on multiple files
« Reply #14 on: September 25, 2020, 08:57:55 AM »
The following should give you what you want. -i.e. "Processing [21/100]: c:\temp\mydrawing.dwg"

Code - Bash: [Select]
  1. @echo off
  2. :: process files given as argument to this batch script.
  3. ::
  4. :: Last Updated: 09.25.20 7:51:30 AM
  5. ::
  6. :: BY: John Kaul
  7.  
  8. set script="%~dp0\BatchDrawings_accoreconsole.scr"
  9. set script=%script:\\=\%
  10. :: - Create an argument counter for prompting.
  11. set argc=0
  12. set count=1
  13. :: - Find out how many arguments we have.
  14. for %%x in (%*) do set /A argc+=1
  15.  
  16. :processArgs
  17.         if [%1]==[] goto endmark
  18.         title "%~f1"
  19.         call "C:\Program Files\Autodesk\AutoCAD 2021\accoreconsole.exe" /i "%~f1" /s %script% /l en-US >"C:\temp\cleanup.log"
  20.         echo Processing [%count%/%argc%]: %~f1
  21.         set /A count +=1
  22.         if errorlevel 1 goto errormark
  23.         SHIFT
  24.         goto processArgs
  25. :errormark
  26.         echo.
  27.         echo.
  28.         echo ERROR processing %~f1
  29.         pause
  30.         echo.
  31. :endmark
  32. rem
  33. rem     finished
  34. rem
  35.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

framednlv

  • Newt
  • Posts: 64
Re: Batch operations on multiple files
« Reply #15 on: September 25, 2020, 09:45:41 AM »
Thanks, that works great.
One other thing, can you help with filtering .dwg files only?

Thanks,
Chris
« Last Edit: September 25, 2020, 10:03:09 AM by framednlv »

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Batch operations on multiple files
« Reply #16 on: September 25, 2020, 11:14:03 AM »
It would probably be better to let the program crash for those that try to launch this on a file other than a DWG but I'll play along (-i.e. only drag and drop only DWGs).

Two minor changes:
1. Added a filter on the argument counter.
2. Added a simple if then statement in the recursive function.

Code - Bash: [Select]
  1. @echo off
  2. :: process files given as argument to this batch script.
  3. ::
  4. :: Last Updated: 09.25.20 10:08:55 AM
  5. ::
  6. :: BY: John Kaul
  7.  
  8. set script="%~dp0\BatchDrawings_accoreconsole.scr"
  9. set script=%script:\\=\%
  10. :: - Create an argument counter for prompting.
  11. set argc=0
  12. set count=1
  13. :: - Find out how many arguments we have.
  14. for %%x in ("%*.dwg") do set /A argc+=1
  15.  
  16. :processArgs
  17.         if [%1]==[] goto endmark
  18.         if NOT [%~x1]==[.dwg] goto endmark
  19.         title "%~f1"
  20.         call "C:\Program Files\Autodesk\AutoCAD 2021\accoreconsole.exe" /i "%~f1" /s %script% /l en-US >"C:\temp\cleanup.log"
  21.         echo Processing [%count%/%argc%]: %~f1
  22.         set /A count +=1
  23.         if errorlevel 1 goto errormark
  24.         SHIFT
  25.         goto processArgs
  26. :errormark
  27.         echo.
  28.         echo.
  29.         echo ERROR processing %~f1
  30.         pause
  31.         echo.
  32. :endmark
  33. rem
  34. rem     finished
  35. rem
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

framednlv

  • Newt
  • Posts: 64
Re: Batch operations on multiple files
« Reply #17 on: September 26, 2020, 02:02:05 PM »
This seems to work:
Code: [Select]
if /I [%~x1]==[.DWG] (echo "[%count%/%argc%]: Processing... %~f1" ) else (echo "[%count%/%argc%] skipping %~f1" )
if /I [%~x1]==[.DWG] (call "C:\Program Files\Autodesk\AutoCAD 2021\accoreconsole.exe" /i "%~f1" /s %script% /l en-US >"C:\temp\cleanup.log")

There is one problem I found.  If any of the file names or folders have the '&' character it doesn't work.

 
« Last Edit: September 28, 2020, 02:44:04 PM by framednlv »

framednlv

  • Newt
  • Posts: 64
Re: Batch operations on multiple files
« Reply #18 on: September 29, 2020, 09:57:58 AM »
I was able to put together a VBS script that does the same as the previously posted bat file.  This will allow you to drag and drop files or a folder to create the bat file, and will run it.  It will skip files that are not dwg files and handles the file names better than the previously posted one.

select and save as a .vbs file:
Code - Visual Basic: [Select]
  1. Set objArgs = Wscript.Arguments
  2. Set objFso = createobject("scripting.filesystemobject")
  3. set oShell = CreateObject("Shell.Application")
  4. strFile_Path = "C:\temp\Cleanup.bat"
  5. accoreconsole = "C:\Program Files\Autodesk\AutoCAD 2021\accoreconsole.exe"      'Put your current autocad path here
  6. scriptFile = "x:\Lisp\BatchCleanup\BatchCleanup.scr"    'Put path to script file here
  7.  
  8. dim filesys, newfolder
  9. set filesys=CreateObject("Scripting.FileSystemObject")
  10. If Not filesys.FolderExists("C:\Temp\") Then
  11.         newfolder = filesys.CreateFolder ("C:\Temp\")
  12. End If
  13.  
  14.  
  15. Set filesys = CreateObject("Scripting.FileSystemObject")
  16. filesys.CreateTextFile("C:\temp\Cleanup.bat"), True
  17. If filesys.FileExists("C:\temp\Cleanup.bat") Then
  18.         filesys.DeleteFile "C:\temp\Cleanup.bat"
  19. End If  
  20.  
  21. 'iterate through all the arguments passed
  22. For i = 0 to objArgs.count
  23.         on error resume next
  24.        
  25. 'try and treat the argument like a folder
  26.         Set folder = objFso.GetFolder(objArgs(i))
  27.        
  28. 'if we get an error, we know it is a file
  29.         If err.number <> 0 then
  30. 'this is not a folder, treat as file
  31.                 ProcessFile(objArgs(i))
  32.         Else
  33.                
  34. 'No error? This is a folder, process accordingly
  35.                 For Each file In folder.Files
  36.                         ProcessFile(file.path)
  37.                 Next
  38.         End if
  39.         On Error Goto 0
  40. Next
  41.  
  42. Function ProcessFile(sFilePath)
  43.         Const ForReading = 1, ForWriting = 2, ForAppending = 8
  44.         Dim fso, f
  45.         Set fso = CreateObject("Scripting.FileSystemObject")
  46.         Set f = fso.OpenTextFile(strFile_Path, ForAppending, True)
  47.         f.write "@echo off" & vbCrLf
  48.         f.write "Title Please wait while I clean up here..." & vbCrLf
  49.         if UCASE(Mid(sFilePath,len(sFilePath)-3,4)) = ".DWG" then
  50.                 f.write "@echo [" & i+1 & "/" & objArgs.count & "]: Processing... " & sFilePath & vbCrLf
  51.                 f.write Chr(34) & accoreconsole & Chr(34) & " /i " & Chr(34) & sFilePath & Chr(34) & " /s " & Chr(34) & scriptFile & Chr(34) & " " & ">C:\temp\cleanup.log" & vbCrLf
  52.                 f.Close
  53.         Else
  54.                 f.write "@echo off" & vbCrLf
  55.                 f.write "@echo [" & i+1 & "/" & objArgs.count & "]: Skipping... " & sFilePath & vbCrLf
  56.                 f.Close
  57.         End If
  58. End Function
  59.  
  60. Dim shell
  61. Set shell = CreateObject("WScript.Shell")
  62. shell.Run strFile_Path
  63.  
  64.  

A side note, I'm not a programmer so the code might not be perfect.



EDIT (John): Corrected code tag language.
« Last Edit: September 29, 2020, 10:54:08 AM by John Kaul (Se7en) »

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
Re: Batch operations on multiple files
« Reply #19 on: September 29, 2020, 11:06:24 AM »
Sorry, I didn't get around to addressing your previous post.

Nice script!

Your line #49 can be cleaned up a bit by using a separate function like the following:

Code - Visual Basic: [Select]
  1. Function getExtension(filespec)
  2.   Dim fso
  3.   Set fso = CreateObject("Scripting.FileSystemObject")
  4.   Set f = fso.GetFile(filespec)
  5.  
  6.   getExtension = fso.GetExtensionName(filespec)
  7. End Function

Use like this:

Code - Visual Basic: [Select]
  1. If(UCase(getExtension(sFilePath))="DWG") Then 'proceed

I do not like line #39; would you be open to a bit of a restructure of the code block of lines 22-39?
You could add a SELECT CASE (-i.e. COND in autolisp) to do some prompting of misc errors and then eventually just quit the script after the for loop.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

framednlv

  • Newt
  • Posts: 64
Re: Batch operations on multiple files
« Reply #20 on: September 29, 2020, 11:38:11 AM »
Please feel free to add/edit/change anything in the code. 

Edit:
I'm going through your comments with more than 1/2 a cup of coffee.


Thanks,
Chris
« Last Edit: September 29, 2020, 03:17:50 PM by framednlv »

framednlv

  • Newt
  • Posts: 64
Re: Batch operations on multiple files
« Reply #21 on: September 29, 2020, 04:15:58 PM »
Sorry, I didn't get around to addressing your previous post.

Nice script!

Your line #49 can be cleaned up a bit by using a separate function like the following:

Code - Visual Basic: [Select]
  1. Function getExtension(filespec)
  2.   Dim fso
  3.   Set fso = CreateObject("Scripting.FileSystemObject")
  4.   Set f = fso.GetFile(filespec)
  5.  
  6.   getExtension = fso.GetExtensionName(filespec)
  7. End Function

Use like this:

Code - Visual Basic: [Select]
  1. If(UCase(getExtension(sFilePath))="DWG") Then 'proceed

I do not like line #39; would you be open to a bit of a restructure of the code block of lines 22-39?
You could add a SELECT CASE (-i.e. COND in autolisp) to do some prompting of misc errors and then eventually just quit the script after the for loop.
John,
Thank you for your comments.
I changed/added the getExtension function.  I also noticed the Echo command was erroring with the "&" symbol, so I added quotes to the file name.

I'm not sure what you had in mind for "restructure of the code block of lines 22-39".

I did notice the script doesn't do well with the count when dropping the folder on the script, it list every file as [1/1].  The other item is that it does not do sub folders and this would be nice.  Any thoughts on these two items?

Thanks,
Chris

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: Batch operations on multiple files
« Reply #22 on: September 30, 2020, 02:42:19 PM »
This seems to work:
Code: [Select]
if /I [%~x1]==[.DWG] (echo "[%count%/%argc%]: Processing... %~f1" ) else (echo "[%count%/%argc%] skipping %~f1" )
if /I [%~x1]==[.DWG] (call "C:\Program Files\Autodesk\AutoCAD 2021\accoreconsole.exe" /i "%~f1" /s %script% /l en-US >"C:\temp\cleanup.log")

There is one problem I found.  If any of the file names or folders have the '&' character it doesn't work.

People who insist on using special characters in file names are a problem, not the names themselves.  But I'm a little old school.   :crazy2:
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

framednlv

  • Newt
  • Posts: 64
Re: Batch operations on multiple files
« Reply #23 on: September 30, 2020, 04:24:53 PM »

People who insist on using special characters in file names are a problem, not the names themselves.  But I'm a little old school.   :crazy2:

Yea, we can't tell people that hire us what to do or not do.