Zoom to paper borders in paper space/layout

Zoom to paper borders in paper space/layout

mailGD7M4
Explorer Explorer
3,982 Views
8 Replies
Message 1 of 9

Zoom to paper borders in paper space/layout

mailGD7M4
Explorer
Explorer

Hello

 

I'm searching a way to automatically zoom to the borders of the "paper" or "plot-area" in paper space/in a layout - even when there are objects outside this area so "Zoom to extents" or "Zoom all" don't always do the job properly.

 

I have to process several thousand files which are made and saved through the last two decades (varying templates, varying paper sizes) . I've written an Auto Lisp script which I can run on all these files in a row using a batch plugin. It's nearly finished, but one the tasks is to save the file with the first layout active (that's done) and zoomed to show the the paper in the maximum possible size. The intention is, that  the preview thumbnail of the dwg in the windows explorer shows the page / its content at maximum possible size and as few as possible of the objects that are placed around the actual plot area / paper (e.g. tables to show which custom dictionaries are present, ...). With "Zoom to extents" or "Zoom all" I often get a result that's far to much zoomed out ...

 

I'd be grateful for some advice!

Thomas 

0 Likes
Accepted solutions (1)
3,983 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution
(defun C:ZL (); Zoom Limits
  (command "_.zoom" (getvar 'limmin) (getvar 'limmax))
  (princ)
)

 

 

The plotting area is the "limits" in paper space.  The above Zooms to the Limits by using their defined corners as a Zoom window.

 

If you want to Zoom to the Limits in All Layouts in the drawing, in one command, use the ZLAL command in the attached.  [It leaves you at the end in Model Space, but could probably be altered to leave you in the first Paper Space Layout, or to skip Model Space entirely.]

Kent Cooper, AIA
Message 3 of 9

Sea-Haven
Mentor
Mentor

There is a subtle flaw if you make the mview say way bigger than the current plot window it will not zoom to the true outside area. Whilst zoom e will work it has the disadvantage of zooming any junk say out side of a title block. You must do plot and "Apply" to reset the plot area then cancel plot, if using a correct dwt with layout plot area set up correctly with a title block, then ignore everything I have said.

 

For me as I use a fixed size titleblock in layouts zoom -6,-6 810,590 subtly outside the title block.

Message 4 of 9

mailGD7M4
Explorer
Explorer

Thanks a lot Kent this is what I was looking for! I tested it on 10 random files where zoom e did not perform to my needs and it worked every time up to now. Great!

0 Likes
Message 5 of 9

mailGD7M4
Explorer
Explorer

Hi sea.heaven, thanks for your input. I'll keep it in mind. I did some tests and up to now it worked perfect.

0 Likes
Message 6 of 9

ronjonp
Advisor
Advisor

Assuming you use a block for a titleblock, give this a try:

(defun c:zal (/ _bigblock a b c d)
  ;; RJP » 2020-07-08
  (defun _bigblock (s / mn mx)
    (if	s
      (car (vl-sort
	     (mapcar '(lambda (x)
			(vla-getboundingbox (vlax-ename->vla-object x) 'mn 'mx)
			(list (distance (vlax-safearray->list mn) (vlax-safearray->list mx)) mn mx)
		      )
		     (mapcar 'cadr (ssnamex s))
	     )
	     '(lambda (r j) (> (car r) (car j)))
	   )
      )
    )
  )
  (setq d (vla-get-activedocument (setq a (vlax-get-acad-object))))
  (setq c (getvar 'ctab))
  (foreach x (layoutlist)
    (setvar 'ctab x)
    (vlax-put d 'mspace 0)
    ;; If we have a block on the tab
    (if	(setq b (_bigblock (ssget "_x" (list '(0 . "insert") (cons 410 x)))))
      ;; Zoom to the largest block bounding box
      (vla-zoomwindow a (cadr b) (caddr b))
      ;; Else zoom extents
      (vla-zoomextents a)
    )
  )
  (setvar 'ctab c)
  (princ)
)
0 Likes
Message 7 of 9

Sea-Haven
Mentor
Mentor

Ronjonp good idea we took any one who put the title block not on 0,0 outside and there name became mud at staff meetings.

 

Thats why the window option, did have move all our titles to 0,0.

 

One suggestion go to say 1st layout pick title block if junk block is in paper space and bigger than title block will zoom incorrect. Or if known title blocks make a list and search.

0 Likes
Message 8 of 9

ronjonp
Advisor
Advisor

@Sea-Haven  The options on this are based on the assumption that the OP uses block/xref titleblocks. I don't ever have anything else outside of the titleblock in paperspace much less a block larger than a titleblock. Do you do this?

0 Likes
Message 9 of 9

Sea-Haven
Mentor
Mentor

Very rare but occasionally would have something outside title block, and as title block was company std always at 1:1 so window worked.

0 Likes