Save changes to page setup

Save changes to page setup

iwafb
Advisor Advisor
666 Views
8 Replies
Message 1 of 9

Save changes to page setup

iwafb
Advisor
Advisor

Hi All,

 

I've managed to (very badly) make changes to a page setup. However, they seem to only change the page setup and not carry through to the plot... I'm sure it's probably missing a simple step, but visual lisp is a bit foreign to me so i'm gessing a lot...

 

;; Get the current drawing
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

;; Get the PlotConfigurations collection
(setq plotCfgs (vla-get-PlotConfigurations doc))

(setq plotCfg (vl-catch-all-apply 'vla-Item (list plotCfgs "DWG to PDF pc3")))

;initializing window to plot
(if (= (getvar "ctab") "A4")(vlax-invoke plotCfg 'SetWindowToPlot '(0.0 0.0) '(297.0 210.0)))
(if (= (getvar "ctab") "A3")(vlax-invoke plotCfg 'SetWindowToPlot '(0.0 0.0) '(420.0 297.0)))
(if (= (getvar "ctab") "A2")(vlax-invoke plotCfg 'SetWindowToPlot '(0.0 0.0) '(594.0 420.0)))
(if (= (getvar "ctab") "A1")(vlax-invoke plotCfg 'SetWindowToPlot '(0.0 0.0) '(841.0 594.0)))
(if (= (getvar "ctab") "A0")(vlax-invoke plotCfg 'SetWindowToPlot '(0.0 0.0) '(1189.0 841.0)))

(vla-put-PlotType plotCfg acWindow)

;Force landscape orientation
(vla-put-PlotRotation plotCfg ac0degrees)

;; Assign the page setup to the current layout (seems to save the changes...)
(vla-CopyFrom (vla-get-ActiveLayout doc) plotCfg)

 

The problem seems to be that all page setups that had previous "portait" orientation and showing "landscape" in the page setup, but when I try to plot, the page setup doesn't load this change (still shows portait)...

 

Hope this makes sense and someone can help...

 

Cheers.

0 Likes
Accepted solutions (1)
667 Views
8 Replies
Replies (8)
Message 2 of 9

ronjonp
Advisor
Advisor

@iwafb 

All you need to do is apply the landscape rotation to all tabs:

 

(vlax-for layout (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-plotrotation layout 0)
)

I also have THIS which will let you apply a pagesetup to all layouts.

 

0 Likes
Message 3 of 9

iwafb
Advisor
Advisor
Thanks Ron,

I've seen lots of posts about changing a single page setup in multiple layout tabs. My issue is reversed, in that i've got a single layout tab and I want to make changes to multiple page setups.

Turns out that I had a different issue causing the plot to not load the page setup properly... The following code is not pretty, but does what I want...

;;;
;;;A programme to modify all existing page setups from "extent" mode to "window" mode
;;;

;;Function to create a list of available page setups

(defun listpagesetups ()

(setq a(dictsearch(namedobjdict)"ACAD_PLOTSETTINGS"))
(setq b
(vl-remove-if
'(lambda(x)(/=(car x)350)) a)
)

(setq duind 0)
(setq pagelist nil)

(repeat (length b)
(setq pagelist (cons (cdr (assoc 1 (entget(cdr (nth duind b)))))pagelist))
(setq duind (+ duind 1))
)

)

;;Process setups

(defun c:psw ()
(setvar "cmdecho" 0)

;Look for current page setups

(listpagesetups)

;; Get the current drawing
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

;; Get the PlotConfigurations collection
(setq plotCfgs (vla-get-PlotConfigurations doc))


;; Get window for plotting

;Cycle through page setups and modify plot settings

(setq duind 0)

(repeat (length pagelist)

(setq plotCfgName (nth duind pagelist))

(setq plotCfg (vl-catch-all-apply 'vla-Item (list plotCfgs plotCfgName)))

;initializing window to plot
(if (= (getvar "ctab") "A4")(vlax-invoke plotCfg 'SetWindowToPlot '(0.0 0.0) '(297.0 210.0)))
(if (= (getvar "ctab") "A3")(vlax-invoke plotCfg 'SetWindowToPlot '(0.0 0.0) '(420.0 297.0)))
(if (= (getvar "ctab") "A2")(vlax-invoke plotCfg 'SetWindowToPlot '(0.0 0.0) '(594.0 420.0)))
(if (= (getvar "ctab") "A1")(vlax-invoke plotCfg 'SetWindowToPlot '(0.0 0.0) '(841.0 594.0)))
(if (= (getvar "ctab") "A0")(vlax-invoke plotCfg 'SetWindowToPlot '(0.0 0.0) '(1189.0 841.0)))
;(vlax-invoke plotCfg 'SetWindowToPlot 'pt1 'pt2)
(vla-put-PlotType plotCfg acWindow)
(if (= plotCfgName "A3")(vla-put-PlotRotation plotCfg 0))

;; Assign the page setup to the current layout (seems to save the changes...)
(vla-CopyFrom (vla-get-ActiveLayout doc) plotCfg)

(setq duind (+ 1 duind))
)

;;Set current page setup name
(setq plotCfg (vl-catch-all-apply 'vla-Item (list plotCfgs "DWG to PDF pc3")))
;;Apply current page setup
(vla-CopyFrom (vla-get-ActiveLayout doc) plotCfg)

)
0 Likes
Message 4 of 9

ronjonp
Advisor
Advisor
Accepted solution

Well glad you got it figured out. I'm still a bit confused about "(= (getvar "ctab") "*")" within the loop since you mentioned modifying the pagesetups. You are not cycling tabs so all those if statements will always return the same result ( or nothing ).

 

Here is a simple snippet to set all plot configurations to landscape and plot by window:

 

 

(vlax-for plotcfg (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-plotrotation plotcfg 0)
  (vla-put-plottype plotcfg acwindow)
)

 

 

Here are some other examples to mull over:

 

(vlax-for plotcfg (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-plotrotation plotcfg 0)
  (vla-put-plottype plotcfg acwindow)
  ;; Set plot window based on the pagesetup media name
  (cond	((= "A4" (setq c (vla-get-canonicalmedianame plotcfg)))
	 (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(297.0 210.0))
	)
	((= "A3" c) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(420.0 297.0)))
	((= "A2" c) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(594.0 420.0)))
	((= "A1" c) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(841.0 594.0)))
	((= "A0" c) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(1189.0 841.0)))
  )
)
;; Set plot window based current tab name
(setq plotcfg (vla-item	(vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
			(getvar 'ctab)
	      )
)
(cond ((= "A4" (getvar 'ctab)) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(297.0 210.0)))
      ((= "A3" (getvar 'ctab)) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(420.0 297.0)))
      ((= "A2" (getvar 'ctab)) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(594.0 420.0)))
      ((= "A1" (getvar 'ctab)) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(841.0 594.0)))
      ((= "A0" (getvar 'ctab)) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(1189.0 841.0)))
)

 

 

 

 

0 Likes
Message 5 of 9

Sea-Haven
Mentor
Mentor

I have taken a different stance and decide what plot type pdf or hard copy and look at the title block on the current layout and adjust plot window to suit, then use a plot lisp. It works for like various layouts A1, A1, A3, A4, A1 in sequence plotting all in one go at test stage its PDF but printer destination will be added soon.

 

We have plotted for years select printer type only. PDF, A1 large format, A3 Color or B-W, JPG and so on.

0 Likes
Message 6 of 9

iwafb
Advisor
Advisor

@ronjonp wrote:

Well glad you got it figured out. I'm still a bit confused about "(= (getvar "ctab") "*")" within the loop since you mentioned modifying the pagesetups. You are not cycling tabs so all those if statements will always return the same result ( or nothing ).

 

Here is a simple snippet to set all plot configurations to landscape and plot by window:

 

 

 

(vlax-for plotcfg (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-plotrotation plotcfg 0)
  (vla-put-plottype plotcfg acwindow)
)

 

 

 

Here are some other examples to mull over:

 

 

(vlax-for plotcfg (vla-get-plotconfigurations (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-plotrotation plotcfg 0)
  (vla-put-plottype plotcfg acwindow)
  ;; Set plot window based on the pagesetup media name
  (cond	((= "A4" (setq c (vla-get-canonicalmedianame plotcfg)))
	 (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(297.0 210.0))
	)
	((= "A3" c) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(420.0 297.0)))
	((= "A2" c) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(594.0 420.0)))
	((= "A1" c) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(841.0 594.0)))
	((= "A0" c) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(1189.0 841.0)))
  )
)
;; Set plot window based current tab name
(setq plotcfg (vla-item	(vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
			(getvar 'ctab)
	      )
)
(cond ((= "A4" (getvar 'ctab)) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(297.0 210.0)))
      ((= "A3" (getvar 'ctab)) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(420.0 297.0)))
      ((= "A2" (getvar 'ctab)) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(594.0 420.0)))
      ((= "A1" (getvar 'ctab)) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(841.0 594.0)))
      ((= "A0" (getvar 'ctab)) (vlax-invoke plotcfg 'setwindowtoplot '(0.0 0.0) '(1189.0 841.0)))
)

 

 

 

 

 


I did say it wasn't pretty...😂

 

Long story, but we use Advance Steel as a plug in to Autocad. In AS, the drawing borders all have the same name, regardless of page size. So, I've set it up so that the layout tab represents the paper size. From there, I look to see, in the current drawing, what sheet size i'm working with in the current drawing...

 

0 Likes
Message 7 of 9

ronjonp
Advisor
Advisor

Glad you're getting it sorted. Depending on how 'clean' your titleblock is on the tabs you may not even have to identify by a tab name. Look into vla-getboundingbox. If you post a sample drawing I may be able to streamline this a bit further.

 

You can also refactor some of your code like so:

 

(if (setq plt (cond ((= "A4" (setq ct (getvar 'ctab))) '(297.0 210.0))
		    ((= "A3" ct) '(420.0 297.0))
		    ((= "A2" ct) '(594.0 420.0))
		    ((= "A1" ct) '(841.0 594.0))
		    ((= "A0" ct) '(1189.0 841.0))
	      )
    )
  (vlax-invoke plotcfg 'setwindowtoplot '(0. 0.) plt)
)

 

 

 

0 Likes
Message 8 of 9

pbejse
Mentor
Mentor

And another way...

(if (setq plt (cdr (assoc (getvar 'ctab)
			  '(("A4" 297.0 210.0) ("A3" 420.0 297.0)
			    ("A2" 594.0 420.0) ("A1" 841.0 594.0)
			    ("A0" 1189.0 841.0))
			   )
		   )
    	)
  (vlax-invoke plotcfg 'setwindowtoplot '(0. 0.) plt)
)

 

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

This looks for a variable in the title block so works for landscape and portrait.

 

(cond 
((=  blkname "DATABLOCK_A1PORT_V4" )(setq sc "1=1" psize "ISO full bleed A1 (594.00 x 841.00 MM)" ll "-6,-6" ur "577,823" orien "Portrait"))
((=  blkname "DATABLOCK_A2PORT_V4")(setq sc "1=1" psize "ISO full bleed A2 (420.00 x 594.00 MM)" ll "-6,-6" ur "416,591" orien "Portrait"))
((=  blkname "DATABLOCK_A3PORT_V4")(setq sc "1=1" psize "ISO expand A3 (297.00 x 420.00 MM)" ll "-3,-3" ur "280.4,403.5" orien "Portrait"))
((=  blkname "DATABLOCK_A4PORT_V4")(setq sc "1=1" psize "ISO full bleed A4 (210.00 x 297.00 MM)" ll "-6,-6" ur "206,293" orien "Portrait"))
((= blkname "DATABLOCK_A1_V4")(setq sc "1=1" psize "ISO full bleed A1 (841.00 x 594.00 MM)" ll "-6,-6" ur "837,590" orien "Landscape"))
((= blkname "DATABLOCK_A2_V4")(setq sc "1=1" psize "ISO full bleed A2 (594.00 x 420.00 MM)" ll "-6,-6" ur "590,416" orien "Landscape"))
((= blkname "DATABLOCK_A3_V4")(setq sc "1=1" psize "ISO full bleed A3 (420.00 x 297.00 MM)" ll "-6,-6" ur "406.5,283.4" orien "Landscape"))
((= blkname "DATABLOCK_A4_V4")(setq sc "1=1" psize "ISO full bleed A4 (297.00 x 210.00 MM)" ll "-6,-6" ur "293,206" orien "Landscape"))
)
0 Likes