AutoLISP: Apply Current Page Setup To All Layout Tabs

The title of today’s routine pretty much explains what this LISP routine does. You must have the layout tab active with the correct page setup current on that tab as well.

Here’s how:

CPS <enter> To start and run

~enjoy


;; Copy current layout page setup to all layout tabs
(vl-load-com)
(defun c:CPS (/ Adoc Layts clyt)
  (setq	aDoc  (vla-get-activedocument (vlax-get-acad-object))
	Layts (vla-get-layouts aDoc)
	clyt  (vla-get-activelayout aDoc)
  )
  (foreach
	    itm
	       (vl-remove (vla-get-name clyt) (layoutlist))
    (vla-copyfrom (vla-item Layts itm) clyt)
  )
  (princ)
)

About AutoCAD Tips

This blog serves as a knowledge base for myself (and anyone else) so that I can reference tips & tricks that I have learned and also refer others to it as well. I hope that this blog helps you learn at least one tip to make your drafting/design experience better.
This entry was posted in AutoLISP, AutoLISP: Manage, Layout, Paper Space, Printing - Plotting. Bookmark the permalink.

33 Responses to AutoLISP: Apply Current Page Setup To All Layout Tabs

  1. zarko says:

    Am I missing something?? everything is done according to your …”here s how!”… and nothing happens!

  2. Gillian says:

    Hi, is there an article on how to load lisp files?

    Cheers

  3. Gillian says:

    cheers Greg!

  4. Dan says:

    Hi, I have (unfortunately) the necessity to modify into some files (which are used as models) the print style preset.
    These files, which are necessary for the realization of electrical diagrams, have inside hundreds of layout.
    Each layout set default printing parameters, so as “Laser b/n.pc3,” as the paper size “A4” scale “Scale to Fit”, and plot style “Schemi.ctb”, etc. ..

    Is there a way to create a macro (a field unknown to me) or something similar, to automatically change in all the default layout, for example, the printer “Colori.pc3” and the print style in “Schemi_colori.ctb “? And maybe can I choose the fields to modify??

    • AutoCAD Tips says:

      The easiest way to accomplish what you want to do is to create a template drawing that contains a page setup with the .ctb file and printer already set… Then when you open a drawing that does not have this page setup, you simply right click on a layout tab and choose “from template…” then navigate to the template file that you previously created and select what page setup will be applied to the current drawing. Once that page setup has been brought into the drawing – and with that layout tab being the current layout tab you can then use this lisp routine to apply that page setup to all of the layout tabs in the drawing.

      • Dan says:

        Thanks, but I can’t use this lisp because each layout have different plot-windows.
        This lisp reset all plot-windows to the default. :-(

  5. AutoCAD Tips says:

    I also noticed a command PSETUPIN if you put a minus sign in the front of the command it will force autocad to use the command line only version of the command. Therefore you can create a script using this command
    http://www.sonic.net/~odin/lounge/autocad%20tips/page_setups_in_autocad.htm

  6. KrikStar says:

    Brilliant! Thanks for sharing this lisp routine. Particularly helpful today when I was searching for a solution to realising that the plot transparency had to be applied to a page setup across a doc that had dozens of layouts. I’ll be saving your link to my favourites!

  7. Storm says:

    It might not seem to do anything (by command prompt), but it seems to work for me :).

  8. ORgrown says:

    YOU are my new BFF!!!! THANK YOU so much for this!!!! You are my hero today. Thanks!

  9. Dix says:

    If I may trouble you, I need help with your autolisp routine.
    I have one dwg file, under the Plot command in Paper Space, I have configured the Printer/plotter name, paper size, the plot area, Plot scale and Plot style table.
    Now I would like to apply all these plot configuration to the rest of the dwgs (all in Paper Space) in the same folder. I loaded up CPS and ran it, nothing happen. I know I am missing a few crucial steps, much appreciated if you could guide me, as I am not much of a programmer.

    Dix

    • AutoCAD Tips says:

      Sorry for the late response. Did you ever find a solution?

      The routine in the blog post only applies the page setup to all layout tabs in the current drawing.
      The ideal solution is to purge out the old page setups and then apply a new page setup.
      The below routine is from the ADN (Autodesk Developer’s network and does what I thin you are after.
      You will need to have a drawing that has the desired page setup in it. The routine will then need to be customized to point to this file and also call upon the name of the desired page setup.
      ;; Delete page setups and Import a named page setup
      ;; http://adndevblog.typepad.com/autocad/2013/01/visual-lisp-importing-page-setups-from-another-drawing.html
      (vl-load-com)
      (setq *doc* (vla-get-activedocument (vlax-get-acad-object)))

      (defun ImpPgSetups (psname / psfile doc2 colPgSetups1 colPgSetups2 objPgSetup objPgSetup2 sName)
      ; if page setup source file is found,
      (if (setq psfile (findfile "Batch Plot Page Setups.dwg"));;<~~~~~~Adjust file name (dWG) that contains the setup
      (progn
      ;; delete all existing page setups.
      (DelPgSetups)
      ;; import page setups
      (setq doc2 (vla-open
      (vla-get-documents (vlax-get-acad-object)) psfile)
      colPgSetups1 (vla-get-PlotConfigurations *doc*)
      colPgSetups2 (vla-get-PlotConfigurations doc2)
      ) ;setq

      ;;get each page setup in the ACAD_PLOTSETTINGS dictionary
      (vlax-for objPgSetup colPgSetups2
      (setq sName (vlax-get-property objPgSetup 'Name))
      (if (= sName psname)
      (progn
      ;;add the page setup to the current doc
      ;:vlax-true = Model tab only
      (setq objPgSetup2
      (vla-add colPgSetups1 sName :vlax-false))
      (vla-CopyFrom objPgSetup2 objPgSetup)
      )
      ) ;if
      ;release the page setup
      (vlax-release-object objPgSetup)
      ) ;vlax-for
      (vlax-release-object colPgSetups1)
      (vlax-release-object colPgSetups2)
      (vla-close doc2)
      (vlax-release-object doc2)
      ) ;progn
      ) ;if
      )

      (defun DelPgSetups (/ colPgSetups objPgSetup)
      (vl-load-com)
      ;;get the ACAD_PLOTSETTINGS dictionary
      (setq colPgSetups (vla-get-PlotConfigurations *doc*))
      ;;get each page setup in the ACAD_PLOTSETTINGS dictionary
      (vlax-for objPgSetup colPgSetups
      ;delete the page setup from the dictionary
      (vla-delete objPgSetup)
      ;release the page setup
      (vlax-release-object objPgSetup)
      ) ;vlax-for
      (vlax-release-object colPgSetups)
      (princ)
      )

      (defun C:Import_Page_Setups()
      (ImpPgSetups "11x17 Page");; <~~~~~~~Adjust to specify the name of the page setup to import
      )

  10. shamas ali says:

    My question is 1st layout tab insert sheet a3 more 25 layout tab copy in 1st layout sheet .please draw a program autolisp commad .

  11. NAVEED says:

    THANKS FOR THIS LISP

  12. Robert says:

    Thank you so much. I have struggled with this for so long, don’t understand why something like isn’t built into Civil 3D.

  13. Sorin says:

    It’s absolutely fantastic what makes this LISP routine !!!
    I had a drawing with 53 layouts and managed in less than 10 seconds I set page all at once. Very simple and fast. I tested CPS command in AutoCAD 2014 and AutoCAD 2007, and works perfectly. Many thanks from me, Sorin

  14. Baber Beg says:

    Brilliant … exactly what was needed in my moment of despair!!
    Nice one Greg!

  15. Karla says:

    Hello Greg ! This LISP is AWESOME and you are the greatest, the smartest man EVER!!!!!!!!! I’m simply thrilled!

    • AutoCAD Tips says:

      I am very happy that it helped you
      ~Greg

      • Karla says:

        You helped big time! I know it sounds like I’m exaggerating a bit, but I was searching something like this for quite a long time… And there was nothing like this to find. Your blog is extra useful, I will keep following you, have a nice day! :-)

  16. Eddie says:

    This works brilliant thanks. It was so quick I wasn’t sure it worked at first but it did on 100+ sheets!

  17. Richard B Farlow says:

    The lisp changed ALL the layouts, Even the ones set for 11×17.

  18. Bartek M says:

    Very helpful

  19. Lê Quang says:

    When i apply lsp, it pop up ” object was open for read”
    t try to paste link folder contain Lsp to the first tab in Options
    but it didn’t work
    please help
    Thank for ur help and sorry about my English grammar

Leave a reply to shamas ali Cancel reply