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

0 Members and 1 Guest are viewing this topic.

Dave M

  • Newt
  • Posts: 181
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: 116
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

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9463
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)

Donate to TheSwamp.org

Crank

  • Swamp Rat
  • Posts: 1450
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 2018     +     AEC Collection

dgorsman

  • Water Moccasin
  • Posts: 2422
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

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9463
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)

Donate to TheSwamp.org

Dave M

  • Newt
  • Posts: 181
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

  • Mosquito
  • Posts: 10
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.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9463
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)

Donate to TheSwamp.org

framednlv

  • Mosquito
  • Posts: 10
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



John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9463
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)

Donate to TheSwamp.org