I have a task where I have several polygons and I have several data frames in which each has a different temporal image. I have linked the data frames to one main data frame in which I add a polygon and all the data frames zoom to that extent of the main frame and I have to export the map. I have thousands of polygons I have managed to automate the process. Problem is I need to delete the shapefile once the map is exported and add the next shapefile. The remove layer doesn't work and the maps show overlaying boundaries. Code:
folder = "D:\TNIAMP\shapes"
arcpy.env.workspace = folder
mxd = arcpy.mapping.MapDocument("CURRENT")
fcList = arcpy.ListFeatureClasses()
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
for fc in fcList:
shape = arcpy.mapping.Layer(fc)
arcpy.mapping.AddLayer(df, shape)
ext = shape.getExtent()
df.extent = ext
arcpy.RefreshActiveView()
arcpy.mapping.ExportToJPEG(mxd,"D:\TNIAMP\shapes\maps\{0}.jpg".format(Tank_name))
arcpy.mapping.RemoveLayer(df, shape)
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
mxd.save()