I am trying to create a loop so that each layer is produced in its own map.
This is my code:
import arcpy
path = "C:\Users\Et\Documents\ArcGIS\Default.gdb"
mxd=arcpy.mapping.MapDocument(path +"\WinterGritting.mxd")
df=arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyrList =arcpy.mapping.ListLayers(mxd,"",df)[0].name
elements=arcpy.mapping.ListLayoutElements (mxd)
for eachlyr in lyrList:
arcpy.SelectLayerByAttribute_management(eachlyr,'NEW_SELECTION')
df.zoomToSelectedFeatures()
arcpy.SelectLayerByAttribute_management(eachlyr,'CLEAR_SELECTION')
mxd.title=eachlyr.name
arcpy.RefreshActiveView()
arcpy.mapping.ExportToJPEG(mxd, path + "\Routes" + eachlyr.name + "jpg")
del mxd
The Error I get is:
Traceback (most recent call last): File
"C:/Users/Et/Documents/Python", line 9, in
arcpy.SelectLayerByAttribute_management(eachlyr,'NEW_SELECTION') File "C:\Program Files
(x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 6494, in
SelectLayerByAttribute
raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Layer Name or Table View: Dataset L does not exist or is
not supported Failed to execute (SelectLayerByAttribute).
Best Answer
Here's a different way to do this by setting the dataframe equal to the current layer's extent. It a lot more simple. Also, you'd better check your path because it shows the MXD being inside the geodatabase.
Updated for comment.
Add the names of whatever layers you don't want to turn off into the landbase list.