I have a group layer that I have populated with a collection of feature layers. When I right-click on the group layer and select "Zoom to Layer" the view zooms so that I can see the full extents of all of the feature layers. I'd like to be able to do this using ArcPy, but so far I haven't been able to determine the proper method. The group layer doesn't have its own Extents, so I can't set the Extent of the current data frame using
groupLayer.getExtent(). Is there a simple way to replicate what the right-click menu does?
There may also be a case where I want to zoom to only the visible layers inside of the group, so a method that allows me to do that would be even better (seeing as my first case is a special case of this one with all layers set to visible).
The code below shows how I am currently trying to go about this. Essentially I am looping through some collection of datasets that have already been brought into my mxd file to export pictures. The
zoomLyrDict dictionaries contain the layer objects for the group layers that I am using. They are created elsewhere in the code and work correctly, so for instance
zoomLyrDict[tuple([dataset,"Groupview"])] returns a group layer that contains several feature layers.
datasetNames = ["ds1", "ds2", "ds3"] for dataset in datasetNames: groupLyrDict[tuple([dataset, "Groupview"])].visible = True df.extent = zoomLyrDict[tuple([dataset,"Groupview"])].getExtent() # causes an error because the group layer does not have an Extent object arcpy.RefreshActiveView() arcpy.mapping.ExportToTIFF(mxd, outDir + "\\my_view.tif", "PAGE_LAYOUT", resolution = 300, tiff_compression = "NONE") groupLyrDict[tuple([dataset, "Groupview"])].visible = False