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 have asked this question a while back but within arcgis environment without using addin. Now i am trying to do the same task to get pixel value when user click anywhere on screen, to use in later steps. Following pythonaddin button code snippet returns nothing. Any suggestions where is the catch?

class Val(object):
"""Implementation for Pythonaddin_addin.genW (Button)"""
def __init__(self):
    self.enabled = True
    self.checked = False
def onClick(self):
    geog = arcpy.GetParameterAsText(0)
    ras = arcpy.PointToRaster_conversion(geog, "ID", "in_memory/ras", "MAXIMUM", "",30)
share|improve this question
What exactly are you trying to do? The code you have written makes no sense in what little context you have provided. – blah238 Nov 21 '12 at 21:54
I want to get a single pixel value when user click anywhere on map and use that value to create a single pixel raster. – Ibe Nov 21 '12 at 23:56
I learned that i should use tool instead of button for interaction with screen. – Ibe Nov 22 '12 at 0:27
up vote 2 down vote accepted

As you mentioned, you must implement a Tool add-in class instead of a button. Then, write your logic in the class's onMouseDownMap method. The arguments passed in to this method include the X and Y coordinates of the clicked location, in the map's coordinate system.

From there it's basically up to you to figure out what to do in response to that event, but here is a simple function to report the coordinates and cell value at the clicked location for the first raster layer in the first map in the current map document.

def onMouseDownMap(self, x, y, button, shift):
    mxd = arcpy.mapping.MapDocument("CURRENT")
    df = arcpy.mapping.ListDataFrames(mxd)[0]
    layers = arcpy.mapping.ListLayers(mxd, None, df)
    rasterlayer = None
    for layer in layers:
        if layer.isRasterLayer:
            rasterlayer = layer
    if rasterlayer:
        cellvalue =, "{} {}".format(x, y)).getOutput(0)
        pythonaddins.MessageBox("XY: {}, {}\nCell Value: {}".format(x, y, cellvalue), "Results")

Example output:


share|improve this answer
thanks. Its helpful. – Ibe Nov 29 '12 at 4:54
"" should be "arcpy.GetCellValue_management" in the above code. – PolyGeo Mar 26 '13 at 1:38
Either works, try it out. – blah238 Mar 26 '13 at 2:17

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.