I would like to create a button using Python Add-ins that allows the user to select a point on the map then immediately bring up a user prompt checkbox that was created in a separate toolbox. I thought what I wrote would work, but when I click on any point on the map, nothing happens. Is there something wrong with the way my script was written?

This is it:

import arcpy
import pythonaddins

arcpy.env.workspace = "E:/GIS/File_Organization/Data/Points/Points.gdb"
arcpy.env.overwriteOutput = True

class SelectWithinARadius(object):
    """Implementation for Button_from_Point_addin.SelectWithinARadius (Button)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE"
    def onMouseDownMap(self, x, y, button, shift): 
        mxd = arcpy.mapping.MapDocument("CURRENT") #designate map document
        pointGeom = arcpy.PointGeometry(arcpy.Point(x, y), mxd.activeDataFrame.spatialReference) #create point from lat/long
        arcpy.MakeFeatureLayer_management(pointGeom, "point_lyr") #make feature layer from point
        pythonaddins.GPToolDialog(r'E:\GIS\File_Organization\Data\Checkbox_Toolbox\Checkbox.tbx', 'Feature_Selection') #add selection toolbox for user input


If not, was I not installing it correctly? I can also provide the code for the toolbox that I am trying to link through the GPToolDialog if that would help as well.

1 Answer 1


I have had to do this in the past and I think the key to it came from a number of Q&As here including:

My code that resulted was:

import arcpy,pythonaddins

def getSearchDistanceInches(scale, selection_tolerance=4):
    """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 SelectFeature(object):
    """Implementation for SelectAsset.tool (Tool)"""
    def __init__(self):
        self.enabled = True
        self.cursor = 3
        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,"your_layer_name")[0]
        arcpy.SelectLayerByLocation_management(lyr, "INTERSECT", pointGeom, "{0} INCHES".format(searchdistance))
        result = arcpy.GetCount_management(lyr)
        count = int(result.getOutput(0))
        print "Found {0} features".format(count)
  • Thanks a million! I will try this out. Does the search distance only work in inches though because of the spatial reference? I would like to be able to buffer the points in miles if that is possible. Dec 8, 2017 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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