centroid = "SHAPE@XY" spatialref = arcpy.Describe("Location").spatialReference cursor = arcpy.da.SearchCursor("Location", "Subd", centroid, spatialref) row[0] = Subd del row del cursorSolved! Go to Solution.
Yes, I am going with the centroid approach. I took your advice on adding the above script into the add in. But, when clicking on the button, I get the message stating the tool has no parameters. I have been unable to get buttons to work without input parameters.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
df.zoomToSelectedFeatures()
try:
for lyr in arcpy.mapping.ListLayers(mxd):
tlyr = lyr
dsc = arcpy.Describe(tlyr)
sel_set = dsc.FIDSet
if dsc.shapeType == "Polygon":
if len(sel_set) > 0:
with arcpy.da.SearchCursor(tlyr, ("SHAPE@")) as cursor:
for row in cursor:
shape = row[0]
zoomextent = shape.extent
arcpy.AddMessage(lyr.name)
df.extent = zoomextent
arcpy.RefreshActiveView()
except:
print arcpy.GetMessages()
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")
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")