HOW TO
Prior to ArcGIS 10.1, Python could not be used to interact with the ArcGIS interface. Now Python Add-ins give users the ability to create Python written tools that respond to a mouse click.The instructions provided describe how to set up Python Add-in code to capture coordinates with a mouse click.
Note:
Please note, using this feature requires familiarization with the use of the Python Add-ins Wizard. Refer to the Python Add-in Guide Book found in Related Information for information on making add-ins. Click the 'ArcGIS Help 10.1 - What is a Python add-in?' link to get started.
Code:
import arcpy
import pythonaddins
class MC(object):
"""Implementation for MouseClickSample_addin.MCtool (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):
pass
Code:
import arcpy
import pythonaddins
class MC(object):
"""Implementation for MouseClickSample_addin.MCtool (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):
message = "Your mouse clicked:" + str(x) + ", " + str(y)
pythonaddins.MessageBox(message, "My Coordinates")
Article ID:000011690
Get help from ArcGIS experts
Download the Esri Support App