fds = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] for fds in arcpy.mapping.ListLayers(fds): desc = arcpy.Describe(fds) type = desc.shapeType if type == "Polygon": df.extent = fds.getSelectedExtent() else: arcpy.AddMessage("Fields polygon not selected")
Solved! Go to Solution.
lyr = arcpy.mapping.ListLayers(mxd, "", df)[0]
df = arcpy.mapping.ListDataFrames(mxd)[0] lyr = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] desc = arcpy.Describe("Fields") if desc.FIDSet: df.extent = lyr.getSelectedExtent() else: arcpy.AddMessage("Fields polygon not selected")
fds = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] for fds in arcpy.mapping.ListLayers(fds):
for df in arcpy.mapping.ListDataFrames(mxd):
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name == "Fields":
df.extent = lyr.getSelectedExtent()
else:
arcpy.AddMessage("Fields polygon not selected")
for df in arcpy.mapping.ListDataFrames(mxd): for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name == "Fields": df.extent = lyr.getSelectedExtent() elif lyr.name != "Fields": arcpy.AddMessage("Fields polygon not selected")
Perhaps try explicitly stating the false condition with an elif?for df in arcpy.mapping.ListDataFrames(mxd): for lyr in arcpy.mapping.ListLayers(mxd, "", df): if lyr.name == "Fields": df.extent = lyr.getSelectedExtent() elif lyr.name != "Fields": arcpy.AddMessage("Fields polygon not selected")
df = arcpy.mapping.ListDataFrames(mxd)[0] lyr = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] df.extent = lyr.getSelectedExtent()
lyr = arcpy.mapping.ListLayers(mxd, "", df)[0]
df = arcpy.mapping.ListDataFrames(mxd)[0] lyr = arcpy.mapping.ListLayers(mxd, "Fields", df)[0] desc = arcpy.Describe("Fields") if desc.FIDSet: df.extent = lyr.getSelectedExtent() else: arcpy.AddMessage("Fields polygon not selected")