I have a problem with the getExtent function on arcpy
I try to focus on layers that start with letters "ra" and then sets the scale of 50000. i try to use asterisk (*) but the code does not work
import arcpy, os, sys
from arcpy import env
env.workspace = r"C:\Project"
for mxdname in arcpy.ListFiles("*.mxd"):
print mxdname
mxd = arcpy.mapping.MapDocument(r"C:\Project\\" + mxdname)
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "*ra", df)[0]
ext = lyr.getExtent()
df.extent = ext
print 'getExtent'
df.scale = 50000
print 'scale'
mxd.save()
del mxd
Any help will be appreciated.
starts with would be "ra*" you have ends with "*ra" see the listlayers menu example
it don't work.
import arcpy, os, sys
from arcpy import env
env.workspace = r"C:\Project"
for mxdname in arcpy.ListFiles("*.mxd"):
print mxdname
mxd = arcpy.mapping.MapDocument(r"C:\Project\\" + mxdname)
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "r*", df)[0]
ext = lyr.getExtent()
df.extent = ext
print 'getExtent'
mxd.save()
del mxd
Then the question is...did you get an error messages? What do you want listlayers within the for loop? it will return a list object and you can't get the extent of a list only individual layers.
i want arcpy zoom to 2 lyr then get scale of 50k