This question already has an answer here:
I been searching for a way to use this http://forums.arcgis.com/threads/49273-getting-xy-from-mouse-click-using-python tool but print the XY in different coordinate system like WGS 1984 (decimal degrees). I want to do this without changing my data frame and keep it in its original stateplane system. I have created a python addin to display the coordinates in DD but this required the data frame to convert to WGS 84 and back again to its original projection (stateplane). This option does work but cannot be used when editing because it locks the mxd. So what is the python code to find the XY in DD from the mouse click regardless of what projection the data frame is set?
here is what i have so far:
class Sel_Property(object): """Implementation for Notifications_addin.selectproperty (Tool)""" def __init__(self): self.enabled = True self.shape =3 def onMouseDownMap(self, x, y, button, shift): mxd = arcpy.mapping.MapDocument("Current") dataframe_string = mxd.activeView dataframe= arcpy.mapping.ListDataFrames(mxd,dataframe_string) oldspatialref = dataframe.spatialReference spatialref = arcpy.SpatialReference(4326) dataframe.spatialReference = spatialref dataframe.spatialReference = oldspatialref pythonaddins.MessageBox("Your mouse clicked at " + str(x) + " , " + str(y),"My Coordinates:")
Here is the new code if anyone is interested.
mxd = arcpy.mapping.MapDocument("CURRENT") pt = arcpy.PointGeometry(arcpy.Point(x, y), mxd.activeDataFrame.spatialReference) Point = pt.projectAs(arcpy.SpatialReference(4326)) partObj = Point.getPart(0) partObj.X partObj.Y pythonaddins.MessageBox("Your mouse clicked at " + str(partObj.X) + " , " + str(partObj.Y),"My Coordinates:")