zoom extents all layouts with vba

zoom extents all layouts with vba

Anonymous
Not applicable
8,467 Views
5 Replies
Message 1 of 6

zoom extents all layouts with vba

Anonymous
Not applicable

Hi,

 

I want to make a code to zoom extents all layouts in a open drawing.

 

I wrote this but it doesn't work at all:

 

 

Sub zoomextentslayouts()

 

Dim Laytab As AcadLayout  

 

For Each Laytab In ThisDrawing.Layouts  

ZoomExtents  

Next Laytab  

End Sub

 

I'm sure somebody can help me Smiley Happy

 

thanx!

Laszlo

 

 

 

 

0 Likes
Accepted solutions (1)
8,468 Views
5 Replies
Replies (5)
Message 2 of 6

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

Zoom-Extents works for the current view. And within your loop you never made a layout active 😉

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks,

But how can I make the layouts active? (I do not want the names of the layouts in my code).

 

gr. Laszlo

0 Likes
Message 4 of 6

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

e.g. set the CTAB-variable

 

Sub zoomextentslayouts()
   Dim Laytab As AcadLayout
   For Each Laytab In ThisDrawing.Layouts
      Call ThisDrawing.SetVariable("CTAB", Laytab.Name)
      'make sure paperspace is active (and not modelspace in an mview-object)
      If Laytab.Name <> "Model" Then
         If ThisDrawing.MSpace Then ThisDrawing.MSpace = False
      End If
      ZoomExtents
   Next Laytab
End Sub

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
Message 5 of 6

Anonymous
Not applicable

Danke schön Alfred!

It works great!

 

gr. Laszlo

0 Likes
Message 6 of 6

fxcastil
Advocate
Advocate

This example uses the "ActiveLayout" property instaed of the system variable "CTAB"

 

 

 

Sub ZoomExtentsLayouts()

Dim LayTab As AcadLayout

For Each LayTab In ThisDrawing.Layouts

 

  ' this uses the "ActiveLayout" property of the the layouts
   ThisDrawing.ActiveLayout = LayTab

   ' this uses the system variable "CTAB" to select the next layout
   'Call ThisDrawing.SetVariable("CTAB", Laytab.Name)

 

   ' make sure PaperSpace is active and not modelspace in each layout
  ' this is shown on the Paper/Model space tab in each layout

     If LayTab.Name <> "Model" Then
            If ThisDrawing.MSpace Then ThisDrawing.MSpace = False
     End If

    ZoomExtents

   Next LayTab

 

 

End Sub

0 Likes