I have a piece of code I'm using to replace layer sources and then zooms to the new features. The part where I replace the workplace source works, but I can't seem to get it to zoom to the extent of the new features. I'm running ArcMap 10.2.

import arcpy
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers")
lyr = arcpy.mapping.ListLayers(mxd, "BLOCK", df)
df.extent = lyr.getSelectedExtent()
df.scale = 5000
del mxd

I get this error though when I run the script.

Runtime error 
Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File "e:\sw_nt\arcgis\desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "e:\sw_nt\arcgis\desktop10.2\arcpy\arcpy\mapping.py", line 1500, in ListLayers
    result = mixins.MapDocumentMixin(map_document_or_layer).listLayers(wildcard, data_frame)
  File "e:\sw_nt\arcgis\desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 820, in listLayers
    raise TypeError(str(type(dataframe)))
TypeError: <type 'list'>
  • 2
    It's always helpful to include the error--or at least mention that there was an error--in the initial post. Otherwise, we're chasing a moving target.
    – Tom
    Dec 13, 2017 at 18:01

2 Answers 2


Your df variable is a list of data frames. You'll need to grab one--almost certainly the first one. So change the line

df = arcpy.mapping.ListDataFrames(mxd, "Layers")


df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

And, as artwork21 mentioned, you'll need to do the same thing when you ListLayers. However, the current error is from the df line.

You may also need to refresh the map in order to reflect the updates. So, after df.scale = 5000, add the line arcpy.RefreshActiveView().


You do not have the layer rather a list of all layers. You need to loop through the list of layers and find the layer you want to zoom to, try:

df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
for lyr in arcpy.mapping.ListLayers(mxd, "BLOCK", df): # the "BLOCK" parameter is just wildcard filter for the list but does not return a single layer
    if lyr.name == "layerNameYouWantToZoomTo":
        df.extent = lyr.getSelectedExtent()
        # continue on with logic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.