AnsweredAssumed Answered

arcpy.mapping SelectLayerByLocation_management

Question asked by jamesfreddyc on Apr 12, 2013
Latest reply on Apr 12, 2013 by jamesfreddyc
Okay, where is the example to select feature by an extent?

The select with a point geometry was easily found, but come'on --- the select by rectangle tool is already a default tool!  I'd think there'd be an example of how this tool selects features since it's such a common tool!

Any help?

I have this so far which doesn't select anything:

 def onRectangle(self, rectangle_geometry):          mxd = arcpy.mapping.MapDocument("CURRENT")          ext = rectangle_geometry         #Creates a polygon object         a = arcpy.Array()         a.add(ext.lowerLeft)         a.add(ext.lowerRight)         a.add(ext.upperRight)         a.add(ext.upperLeft)         a.add(ext.lowerLeft)         thepoly = arcpy.Polygon(a)          for lyr in arcpy.mapping.ListLayers(mxd):             if lyr.name=="mylayer":                 dlyr = lyr                 arcpy.SelectLayerByLocation_management(dlyr, "INTERSECT", thePoly, "", "NEW_SELECTION")           arcpy.RefreshActiveView()

Outcomes