2

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 groupLyrDict and 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     
2
  • 2
    Have you tried getting the MinX of all layers in the group, repeating for MinY, MaxX and MaxY, and building an extent object? For help with code please always include a code snippet that illustrates what you have tried and where you are stuck.
    – PolyGeo
    Commented Aug 28, 2017 at 19:05
  • Well it seems this question may partially be a result of approaching a problem from one direction for so long that I end up missing some other obvious ways. I think what you're suggesting would work, but I was also hoping there'd be a simpler way that didn't force me to loop through all the layers in my file (it sure would be nice if arcpy had some sort of ListLayersInGroup functionality).
    – gwenger
    Commented Aug 28, 2017 at 20:07

0

Browse other questions tagged or ask your own question.