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.
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: df.zoomToSelectedFeatures() arcpy.RefreshActiveView()
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 df.extent = zoomextent arcpy.RefreshActiveView()
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.isGroupLayer:
for sublyr in lyr:
if dsc.shapeType == "Polygon":
with arcpy.da.SearchCursor(sublyr, "SHAPE@XY")) as cursor:
for row in cursor:
arcpy.AddMessage(str(row))
else:
tlyr = lyr
if dsc.shapeType == "Polygon":
with arcpy.da.SearchCursor(tlyr, ("SHAPE@XY")) as cursor:
for row in cursor:
arcpy.AddMessage(str(row))
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: df.zoomToSelectedFeatures() arcpy.RefreshActiveView()
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 df.extent = zoomextent arcpy.RefreshActiveView() Is it possible to select the polygon, hit a python addin button and zoom to centroid? Or am I required to run the tool by selecting the polygon, entering input parameters, and then zoom to the centroid? I would like to perform the operation without having to enter input parameters. But, I am unsure if Python has this capability.
class ButtonClass_WorkSelection(object):
"""Implementation for MyTools_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd):
tlyr = lyr
dsc = arcpy.Describe(tlyr)
sel_set = dsc.FIDSet
if len(sel_set) > 0:
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()