Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to select a polygon then it must automatically change (calculate) the status to "C". The tool seems to work in the background but nothing actually happens (the status is not updated). I have used the code from this post but nothing actually gets selected. If I have a feature in the layer selected already it does deselect it though.

Below is the code that i am using. Is there something that I have gotten wrong? Thanks for any help.

import arcpy
import pythonaddins

def getSearchDistanceInches(scale, selection_tolerance=3):
    """Returns the map distance in inches that corresponds to the input selection
    tolerance in pixels (default 3) at the specified map scale."""
    return scale * selection_tolerance / 96.0 # DPI used by ArcMap when reporting scale

class tlStatToC(object):
    """Implementation for PythonAddin_addin.tlMapCoods (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
    def onMouseDownMap(self, x, y, button, shift):
        mxd = arcpy.mapping.MapDocument("CURRENT")
        pointGeom = arcpy.PointGeometry(arcpy.Point(x, y), mxd.activeDataFrame.spatialReference)
        searchdistance = getSearchDistanceInches(mxd.activeDataFrame.scale)
        lyr = arcpy.mapping.ListLayers(mxd)[0] # assumes you want to select features from 1st layer in TOC
        arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", pointGeom)
share|improve this question

You left off the search distance argument to SelectLayerByLocation. This is important -- for some reason, without it, a PointGeometry object will never intersect anything, at least in my limited testing.


arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", pointGeom)


arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", pointGeom, "%d INCHES" % searchdistance)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.