Is there a Zoom to Layer command in Python?

17865
2
02-20-2013 06:08 AM
MichaelRivera
Occasional Contributor II
I'd like to be able to add a layer to a mxd, this layer changes weekly (crime points) so I'd like to be able to zoom to the layer but
I can't find a command to do it.  Is there a command to Zoom to Layer?
Tags (2)
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus
see zoomToSelectedFeatures () in the arcpy mapping module
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s300000003000000
0 Kudos
JeffMoulds
Esri Contributor
You can get the extent of the layer and apply it to the data frame:

>>> mxd = arcpy.mapping.MapDocument('current') # using current map, can also use a path to a mxd here
>>> df = arcpy.mapping.ListDataFrames(mxd)[0]
>>> lyr = arcpy.mapping.ListLayers(mxd, 'U.S. States*', df)[0]
>>> ext = lyr.getExtent()
>>> df.extent = ext