Assign a page setup to ALL layout tabs (prior to / or without going into "publish dialog")

Assign a page setup to ALL layout tabs (prior to / or without going into "publish dialog")

johnw
Collaborator Collaborator
1,600 Views
11 Replies
Message 1 of 12

Assign a page setup to ALL layout tabs (prior to / or without going into "publish dialog")

johnw
Collaborator
Collaborator

I have 40 to 50 layout tabs in my drawing and I need a way to assign a page setup to all of them without using the Publish or "Publish" selected layouts. I attempted to use this code below but it doesn't work. Any assistance would be greatly appreciated.

 

(defun c:pagesetupall (/ psname ss i)
(setq psname (getstring "\nEnter page setup name: "))
(setq ss (ssget "X" '((0 . "LAYOUT"))))
(setq i 0)
(while (< i (sslength ss))
(command "_layout" "_s" (ssname ss i) "" psname "")
(setq i (1+ i)))
(princ)
)

 

0 Likes
Accepted solutions (1)
1,601 Views
11 Replies
Replies (11)
Message 2 of 12

paullimapa
Mentor
Mentor

try this (not tested) function (apply_ps "name of pagesetup"):

 

; apply_ps function applies given pagesetup name to all layouts
; argument: pagesetup name
; Example:
; (apply_ps "My Page Setup")
;
(defun apply_ps (pgsnam / putPagesetup lst)
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-page-setup/td-p/9386936
; arguments:
; document - (vla-get-activedocument(vlax-get-acad-object))
; layout - (getvar"ctab")
; setup - existing pagesetup name
; Usage:
; (putPagesetup (vla-get-activedocument(vlax-get-acad-object)) (getvar"ctab") "PageSetup Paper") ; given existing pagesetup name: "PageSetup Paper"
(defun putPagesetup (document layout setup) 
;Jason Piercey
	(if 
		(vl-catch-all-error-p  (vl-catch-all-apply  
			(function  
				(lambda () 
					(vla-copyfrom (vla-item (vla-get-layouts document) layout) (vla-item (vla-get-plotconfigurations document) setup))
				)
			)
		)
	)
	 nil  t  
	)
) ; defun
(foreach itm (layoutlist)
 (putPagesetup (vla-get-activedocument(vlax-get-acad-object)) itm pgsnam)
) ; foreach
) ; defun apply_pagesetups

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 12

johnw
Collaborator
Collaborator

Thanks but not sure how to grab this code and place into a lisp routine. I don't see any defun C: function. I am not that good with coding. Code I pasted into original post was from Open.AI based on my question.

0 Likes
Message 4 of 12

paullimapa
Mentor
Mentor

this is actually designed to be a function. You can save it to searchable AutoCAD folder with name: apply_ps.lsp

Then load it at the command prompt: (load"apply_ps")

Then as I've shown in the code run it like this:

(apply_ps "My Page Setup")

where "My Page Setup" is the name of your Pagesetup.

Then "My Page Setup" will be applied to all your Layouts (not Model tab)

One Caveat: You need to make sure the page setup you apply is designed for Layouts and not Model tab.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 12

johnw
Collaborator
Collaborator
That worked! Thanks for that! Is there anyway you can have it load with a Defun C: Apply_PS then when I could just type Apply_pS, and then it would prompt me "Enter Page Setup Name:". if not no worries. I have a lot of lisp routines loaded inside my acaddoc.lsp file and having act like all the others (without having to add the ( ) at the command line would be fantastic.
0 Likes
Message 6 of 12

paullimapa
Mentor
Mentor

here you go and this modified version will check if you've entered a valid page setup name before executing:

 

; apply_ps function applies given pagesetup name to all layouts
; response to OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/assign-a-page-setup-to-all-layout-tabs-prior-to-or-without-going/m-p/11754621/highlight/false#M443744
(defun c:apply_ps (/ allPageSetupsOfLayoutType psname putPagesetup)
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-page-setup/td-p/9386936
; arguments:
; document - (vla-get-activedocument(vlax-get-acad-object))
; layout - (getvar"ctab")
; setup - existing pagesetup name
; Usage:
; (putPagesetup (vla-get-activedocument(vlax-get-acad-object)) (getvar"ctab") "PageSetup Paper") ; given existing pagesetup name: "PageSetup Paper"
; Jason Piercey
 (defun putPagesetup (document layout setup) 
	(if 
		(vl-catch-all-error-p  (vl-catch-all-apply  
			(function  
				(lambda () 
					(vla-copyfrom (vla-item (vla-get-layouts document) layout) (vla-item (vla-get-plotconfigurations document) setup))
				)
			)
		)
	)
	 nil  t  
	)
 ) ; defun
;;; https://jtbworld.com/autocad-pagesetup-lsp
;;;--- allPageSetupsOfLayoutType function given autocad drawing returns Layout Pagesetups sorted
;;; (allPageSetupsOfLayoutType <AcadDocument>)
;;; (allPageSetupsOfLayoutType (vla-get-activedocument (vlax-get-acad-object)))
;;; credits to Jimmy Bergmark  
  (defun allPageSetupsOfLayoutType (doc / aps)
   (vlax-for pc (vla-get-plotconfigurations doc)
    (if (= (vla-get-ModelType pc) :vlax-false)
      (setq aps (cons (vla-get-name pc) aps))
    )
   )
  (vl-sort aps '<)
 ) ; defun
 (if (> (strlen (setq psname (getstring "\nEnter Page Setup Name: " T))) 0)
  (if (member psname (allPageSetupsOfLayoutType (vla-get-activedocument (vlax-get-acad-object))))
   (progn
    (foreach itm (layoutlist)
     (putPagesetup (vla-get-activedocument(vlax-get-acad-object)) itm psname)
    ) ; foreach
    (princ(strcat"\nPage Setup Name: [" psname "] Successfully Applied to All Layouts."))(princ)
   ) 
   (progn
     (princ(strcat"\nPage Setup Name: [" psname "] Not Found."))(princ)
   )
  )
  (progn
   (princ"\nNo Page Setup Name Entered.")(princ)
  )
 ) ; if
   
) ; defun apply_ps

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 12

pbejse
Mentor
Mentor

@johnw wrote:

I have 40 to 50 layout tabs in my drawing and I need a way to assign a page setup to all of them without using the Publish or "Publish" selected layouts. I attempted to use this code below but it doesn't work. Any assistance would be greatly appreciated.

 


Are you aware you can do that with DwgTrueView?

pbejse_0-1676436756832.png

HTH

 

EDIT: Not sure about multiple layout tabs though, i could be wrong 😄

 

0 Likes
Message 8 of 12

pbejse
Mentor
Mentor

@johnw wrote:

I have 40 to 50 layout tabs in my drawing and I need a way to assign a page setup to all of them w

 


If you're looking for a resource ( to help with learning lsp ), here's a good one ---> pagesetup.lsp Free AutoLISP for AutoCAD from JTB 

Message 9 of 12

johnw
Collaborator
Collaborator

Thank you very much! This work great. I do have a question regarding "defaulting" page setups, vs. seeing the PAGE SETUP NAME ASSIGNED to the layout when you use PLOT command. Even after using your command (and seeing the default page setups all the same in the PUBLISH command (see IMAGE 1), when I go to one tab and type PLOT, the default page setup I assigned by using your command, is not showing up as the page setup. It says "NONE". See IMAGE 2. Is there a difference in setting default as your command does and assigning the page setup from NONE to the default in the PLOT dialog??? Is there a way to actually assign the value of the default the page setup in the PLOT Dialog as well? 

 

 

0 Likes
Message 10 of 12

paullimapa
Mentor
Mentor
Accepted solution

once apply_ps lisp function runs successfully and applies the given page setup to all layouts, then the NONE should no longer show up when you enter the PLOT command.  The default on all the layouts should be the given page setup name you entered.  The issue you're encountering within the PLOT command does not occur for me so I cannot replicate the problem.

As for actually setting all layouts to a default page setup to none, I've modified the lisp function to accommodate. Now when you enter the page setup name "*none*" or "*NONE*" apply_ps will set all layouts back to default page setup of NONE:

; apply_ps function applies given pagesetup name to all layouts
; response to OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/assign-a-page-setup-to-all-layout-tabs-prior-to-or-without-going/m-p/11754621/highlight/false#M443744
(defun c:apply_ps (/ allPageSetupsOfLayoutType psname putPagesetup putPageSetupNone)
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-for-page-setup/td-p/9386936
; arguments:
; document - (vla-get-activedocument(vlax-get-acad-object))
; layout - (getvar"ctab")
; setup - existing pagesetup name
; Usage:
; (putPagesetup (vla-get-activedocument(vlax-get-acad-object)) (getvar"ctab") "PageSetup Paper") ; given existing pagesetup name: "PageSetup Paper"
; Jason Piercey
 (defun putPagesetup (document layout setup) 
	(if 
		(vl-catch-all-error-p  (vl-catch-all-apply  
			(function  
				(lambda () 
					(vla-copyfrom (vla-item (vla-get-layouts document) layout) (vla-item (vla-get-plotconfigurations document) setup))
				)
			)
		)
	)
	 nil  t  
	)
 ) ; defun
; putPageSetupNone function sets page setup to empty string
 (defun putPageSetupNone (layout / dn laydict psn)
  (setq dn (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT"))))
  (setq laydict (dictsearch dn layout))
  (entmod(subst(cons 1 "")(assoc 1 laydict)laydict))
 ) ; defun
;;; https://jtbworld.com/autocad-pagesetup-lsp
;;;--- allPageSetupsOfLayoutType function given autocad drawing returns Layout Pagesetups sorted
;;; (allPageSetupsOfLayoutType <AcadDocument>)
;;; (allPageSetupsOfLayoutType (vla-get-activedocument (vlax-get-acad-object)))
;;; credits to Jimmy Bergmark  
  (defun allPageSetupsOfLayoutType (doc / aps)
   (vlax-for pc (vla-get-plotconfigurations doc)
    (if (= (vla-get-ModelType pc) :vlax-false)
      (setq aps (cons (vla-get-name pc) aps))
    )
   )
  (vl-sort aps '<)
 ) ; defun
 (if (> (strlen (setq psname (getstring "\nEnter Page Setup Name: " T))) 0)
  (if (or
       (member psname (allPageSetupsOfLayoutType (vla-get-activedocument (vlax-get-acad-object))))
       (eq (strcase psname) "*NONE*")
      )
   (progn
    (foreach itm (layoutlist)
     (if (eq (strcase psname) "*NONE*")
      (putPageSetupNone itm)
      (putPagesetup (vla-get-activedocument(vlax-get-acad-object)) itm psname)
	 ) ; if
    ) ; foreach
    (princ(strcat"\nPage Setup Name: [" psname "] Successfully Applied to All Layouts."))(princ)
   ) 
   (progn
     (princ(strcat"\nPage Setup Name: [" psname "] Not Found."))(princ)
   )
  )
  (progn
   (princ"\nNo Page Setup Name Entered.")(princ)
  )
 ) ; if
) ; defun apply_ps

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 11 of 12

johnw
Collaborator
Collaborator
Thanks Paul Li and Jimmy!! you guys rock. That works great!!
0 Likes
Message 12 of 12

paullimapa
Mentor
Mentor

Glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos