AnsweredAssumed Answered

How can I write a python add-in which zooms to each selected polygon after each button click?

Question asked by gisadminsfa on Jul 2, 2015
Latest reply on Jul 2, 2015 by dslamb

I want to have a button in a toolbar which when clicked, zooms to the extent of the next selected polygon. I am not sure whether this tool has been developed yet (although i´m sure it has) and do not know whether it should be a python button, or tool class.


Following code creates a list of selected elements. I want to go to the next row after each mouse click.


mxd = arcpy.mapping.MapDocument('CURRENT')

df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]

Envelopes = [] # store extents here


# find the selection set

SelLayer = arcpy.mapping.ListLayers(mxd,data_frame=df)[0] # first layer

fidSet = arcpy.Describe(SelLayer).FIDSet


if len(fidSet) == 0:

  arcpy.AddMessage("Nothing selected")


  # now cursor through it an get the geometries

  # storing their extents into a list

  with arcpy.da.SearchCursor(SelLayer,"SHAPE@") as SCur:

  for feat in SCur:

  # I'm going to assume polygon/polyline

  Envelopes.append(feat[0].extent) # grab the envelope


  df.extent = Envelopes[0] # first extent



The code creates the list, but how can I use a button zoom to the next row extent?