1

With Python Add-In Wizard I created a ButtonTool with which I:

  1. click in the map
  2. get the coordinates of the mouseclick-location in a dialog with textboxes

I want to receive the coordinates in a textbox to have the possibility to copy and paste the coordinate values (e.g. to use them in a document). I get a crash between TKinter and arcpy like I read in some posts before. Nevertheless I want to ask, if anybody has experience with this and has a suggestion.

Here is my code:

Import Tkinter
class ToolCoord(object):
 def __init__(self):
 self.enabled = True
 self.shape = "NONE" 
 self.cursor = 3
 def onMouseDownMap(self, x, y, button, shift):
 pt = arcpy.PointGeometry(arcpy.Point(x,y))
 main = Tkinter.Tk()
 lb = Tkinter.Label(main, text = "UTM-Koordinaten:")
 lb.pack()
 t1 = Tkinter.Text(main, width=20, height=0)
 t1.insert("end", str(x))
 t1.pack()
 t2 = Tkinter.Text(main, width=20, height=0)
 t2.insert("end", str(y))
 t2.pack()
 main.mainloop()
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 17, 2015 at 16:02
2
  • 1
    Write to a temp text file and open it with notepad or write directly to the clipboard. Commented Dec 18, 2015 at 20:30
  • @Luke: Thank you for the hint. That was a smart and simple solution. I made it with the Notepad. Commented Feb 17, 2016 at 13:26

2 Answers 2

2

Tkinter and Esri Python Addins do not play nice together. You can use Tkinter within scripting with Acrpy, but it will usually crash when implemented in an Addin. wxPython GUIs will work within an ESRI Addin. However these will require the end user of your Addin to have wxPython installed on their machine.

answered Dec 17, 2015 at 16:23
1

Based on the hint of Luke I use now a eventbutton with the following code:

class ToolClass71(object):
 """Implementation for Python_Addins_addin.tool (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.
 self.cursor = 3
 def onMouseDownMap(self, x, y, button, shift):
 pt = arcpy.PointGeometry(arcpy.Point(x,y))
 # set environment
 mxd = arcpy.mapping.MapDocument('current')
 mxdpath = mxd.filePath
 df = arcpy.mapping.ListDataFrames(mxd)[0]
 outWorkspace = os.path.dirname(mxdpath)
 # creating a temp feature in the memory space
 tempitem = arcpy.CreateFeatureclass_management("in_memory","item","POINT","","DISABLED","DISABLED","Arch_Denkmal_DSch")
 # add and populatin fields with coordinates
 fields = ["x_coords","y_coords"] 
 i = 0 
 for x in fields: 
 arcpy.AddField_management(tempitem, x, "DOUBLE")
 i = i + 1
 arcpy.da.InsertCursor(tempitem, ["SHAPE@XY"]).insertRow([pt])
 out_file = os.path.join(outWorkspace,"Koordinaten.txt")
 value=["x_coords","y_coords"]
 in_table = tempitem
 # export to csv
 arcpy.ExportXYv_stats(in_table,value,"SPACE",out_file,"ADD_FIELD_NAMES")
 # change rows and colums
 with open(out_file) as f:
 lis = [x.split() for x in f]
 with open(out_file, 'wb') as f:
 # Überschreiben der alten Datei mit den neuen Reihen
 writer = csv.writer(f)
 writer.writerows(zip(*lis))
 # csv öffnen
 subprocess.call(['C:/Windows/System32/notepad.exe', out_file])
 # delete temp objects and refresh active view
 arcpy.Delete_management("in_memory")
 arcpy.Delete_management("Koordinaten")
 arcpy.Delete_management(out_file)
 arcpy.Delete_management(outWorkspace+"\Koordinaten.xml")
 arcpy.RefreshActiveView()
answered Mar 1, 2016 at 10:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.