Author Topic: Changing Plotter for Many Files in Multiple Directories  (Read 8045 times)

0 Members and 1 Guest are viewing this topic.

Rob...

  • King Gator
  • Posts: 3824
  • Take a little time to stop and smell the roses.
Changing Plotter for Many Files in Multiple Directories
« on: September 04, 2012, 03:46:28 PM »
I have many files in multiple directories that need the plotters changed. For some reason, the .pc3 files for our OCE plotters causes a very long delay in the plot (and page set up) dialog box coming up. I was wondering if it is possible to do this as batch routine of some sort.
CAD Tech

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Plotter for Many Files in Multiple Directories
« Reply #1 on: September 04, 2012, 04:03:46 PM »
Maybe this will help: http://www.theswamp.org/index.php?topic=42422.msg476061#msg476061

Or maybe something as simple as this:

Code: [Select]
(defun _foo (doc old new)
  (vlax-for x (vla-get-layouts doc)
    (if (wcmatch (strcase (vla-get-configname x)) (strcase old))
      (vl-catch-all-apply 'vla-put-configname (list x new))
    )
  )
)
(_foo (vla-get-activedocument (vlax-get-acad-object)) "oldoce.pc3" "newoce.pc3")
« Last Edit: September 04, 2012, 04:13:58 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Rob...

  • King Gator
  • Posts: 3824
  • Take a little time to stop and smell the roses.
Re: Changing Plotter for Many Files in Multiple Directories
« Reply #2 on: September 05, 2012, 07:26:50 AM »
Thank you. Excuse my ignorance of code but could you explain to me what it does? I see where it switches the plotter names (that I would replace with mine). Is it a batch routine or would I have to open each drawing manually?
CAD Tech

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Plotter for Many Files in Multiple Directories
« Reply #3 on: September 05, 2012, 09:30:30 AM »
Thank you. Excuse my ignorance of code but could you explain to me what it does? I see where it switches the plotter names (that I would replace with mine). Is it a batch routine or would I have to open each drawing manually?

The code cycles through the layout tabs and looks for a configuration name that you specify. I can put something together that will batch this in a bit via object dbx.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Rob...

  • King Gator
  • Posts: 3824
  • Take a little time to stop and smell the roses.
Re: Changing Plotter for Many Files in Multiple Directories
« Reply #4 on: September 05, 2012, 09:35:24 AM »
That would be cool and very much appreciated.
CAD Tech

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Plotter for Many Files in Multiple Directories
« Reply #5 on: September 05, 2012, 11:50:35 AM »
Here you go. This will process a directory and its subdirectories.
You will need to specify your old and new plotters at the top of the code.
A log file is created so you can check what files were actually changed.
Please run this on some dummy data first.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:changepc3
  2.        (/ _openfile _subfolders _getdirectory dir doc folders l logfile new odbx old save v)
  3.   ;; Change this value - ie. { "old.pc3" or "\\\\servername\\oldsharedprintername" }
  4.   (setq old "old.pc3")
  5.   ;; Change this value - ie. { "new.pc3" or "\\\\servername\\newsharedprintername" }
  6.   (setq new "new.pc3")
  7.   (defun _openfile (file / sh)
  8.     (if (findfile file)
  9.       (progn (setq sh (vlax-get-or-create-object "Shell.Application"))
  10.              (vlax-invoke-method sh 'open (findfile file))
  11.              (vlax-release-object sh)
  12.              file
  13.       )
  14.     )
  15.   )
  16.   (defun _getdirectory (message / sh folder result)
  17.     (setq sh (vlax-get-or-create-object "Shell.Application"))
  18.     (setq folder (vlax-invoke-method sh 'browseforfolder 0 message 0))
  19.     (if folder
  20.       (progn (setq result (vlax-get-property (vlax-get-property folder 'self) 'path))
  21.              (if (/= (substr result (strlen result)) "\\")
  22.                (setq result (strcat result "\\"))
  23.                result
  24.              )
  25.       )
  26.     )
  27.   )
  28.   (defun _subfolders (path / folder fs lst subs)
  29.     (setq fs (vlax-get-or-create-object "Scripting.FileSystemObject"))
  30.     (if
  31.       (and (setq folder (vlax-invoke fs 'getfolder path)) (setq subs (vlax-get folder 'subfolders)))
  32.        (mapcar (function (lambda (x) (cons x (apply 'append (_subfolders x)))))
  33.                (vlax-for sub subs (setq lst (cons (strcat (vlax-get sub 'path) "\\") lst)))
  34.        )
  35.     )
  36.   )
  37.   (cond
  38.     ((not (setq odbx (if (< (setq v (substr (getvar 'acadver) 1 2)) "16")
  39.                        (vla-getinterfaceobject doc "ObjectDBX.AxDbDocument")
  40.                        (vla-getinterfaceobject doc (strcat "ObjectDBX.AxDbDocument." v))
  41.                      )
  42.           )
  43.      )
  44.      (princ "\nObject DBX interface not created!")
  45.     )
  46.     ((if (and (setq dir (_getdirectory "Choose a folder to process (subfolders processed too)..."))
  47.               (and (setq folders (apply 'append (_subfolders dir)))
  48.                    (setq folders (append (list dir) folders))
  49.               )
  50.               (setq logfile (open (setq l (strcat dir "logfile.csv")) "w"))
  51.          )
  52.        (progn
  53.          (write-line "FILE,TABS UPDATED,SAVED" logfile)
  54.          (foreach folder folders
  55.            (foreach file (vl-directory-files folder "*.dwg" 0)
  56.              (if (vl-catch-all-error-p
  57.                    (vl-catch-all-apply 'vla-open (list odbx (strcat folder file)))
  58.                  )
  59.                (write-line (strcase (strcat "!!Error opening: " (strcat folder file))) logfile)
  60.                (progn
  61.                  (setq save 0)
  62.                  (vlax-for x (vla-get-layouts odbx)
  63.                    (if (wcmatch (strcase (vla-get-configname x)) (strcase old))
  64.                      (progn (and (not (vl-catch-all-error-p
  65.                                         (vl-catch-all-apply 'vla-put-configname (list x new))
  66.                                       )
  67.                                  )
  68.                                  (setq save (1+ save))
  69.                             )
  70.                      )
  71.                    )
  72.                  )
  73.                  (if (zerop save)
  74.                    (write-line (strcat (strcat folder file "," (itoa save) ",NO")) logfile)
  75.                    (progn (write-line (strcat (strcat folder file "," (itoa save) ",YES")) logfile)
  76.                           (vla-saveas odbx (vla-get-name odbx))
  77.                    )
  78.                  )
  79.                )
  80.              )
  81.            )
  82.          )
  83.          (close logfile)
  84.          (_openfile l)
  85.        )
  86.      )
  87.     )
  88.   )
  89.   (princ)
  90. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Plotter for Many Files in Multiple Directories
« Reply #6 on: September 06, 2012, 08:59:14 AM »
Did this work for you?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Rob...

  • King Gator
  • Posts: 3824
  • Take a little time to stop and smell the roses.
Re: Changing Plotter for Many Files in Multiple Directories
« Reply #7 on: September 07, 2012, 07:13:02 AM »
Mr. Jonp,

Thank you for this. Sorry to leave you hanging but I was out sick for a couple days. I will definitely give this a trial run, hopefully today if I get caught up enough.
CAD Tech

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Plotter for Many Files in Multiple Directories
« Reply #8 on: September 07, 2012, 08:54:34 AM »
Mr. Jonp,

Thank you for this. Sorry to leave you hanging but I was out sick for a couple days. I will definitely give this a trial run, hopefully today if I get caught up enough.

No worries .. let me know how it goes.  :-) Hope you feel better.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Rob...

  • King Gator
  • Posts: 3824
  • Take a little time to stop and smell the roses.
Re: Changing Plotter for Many Files in Multiple Directories
« Reply #9 on: September 10, 2012, 11:39:32 AM »
It works. Because some people don't know how to not change page set-ups, I changed the old name to "*". Worked like a charm.
CAD Tech

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Changing Plotter for Many Files in Multiple Directories
« Reply #10 on: September 10, 2012, 11:50:27 AM »
It works. Because some people don't know how to not change page set-ups, I changed the old name to "*". Worked like a charm.

 8-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC