Copying XY to clipboard using Python Add-In

3568
2
10-22-2014 01:49 AM
PeterLovenski
New Contributor

Hi guys,

 

I am trying to create a simple tool to copy XY from where i click the mouse button. What i have done already is:

 

1. create add-in files using Python Add-In Wizard

2. create toolbar and tool inside it

 

in *.py file i got:

 

import arcpy import pythonaddins import win32clipboard as clipboard   class p_tool(object):     """Implementation for python-add-in-proj_addin.tool (Tool)"""     def __init__(self):         self.enabled = True         self.shape = "NONE"      def onMouseDownMap(self, x, y, button, shift):         button = 1         shift  = 2         clipboard.OpenClipboard()         clipboard.EmptyClipboard()         xy = str(x1)+' '+str(y1)         clipboard.SetClipboardData(xy, clipboard.CF_TEXT)         clipboard.closeClipboard()         message = xy         pythonaddins.MessageBox(message, "My Coordinates", 0) 

 

 

About win32clipboard - i tested in in python windon in ArcMap and I am able to import it and openclipboard() but emptyclipboard() does not work and gives me that error:

 

File "<string>", line 1, in <module>

error: (1418, 'EmptyClipboard', 'Thread does not have a clipboard open.')

 

thanks for your help!

0 Kudos
2 Replies
JasonScheirer
Occasional Contributor III

You probably don't need to bother with the .EmptyClipboard() call at all, I'd assume SetClipboardData would just overwrite it if needed. Also make sure you correctly case CloseClipboard() in your code, it's closeClipboard() in your source right now.

0 Kudos
DuncanHornby
MVP Notable Contributor

Added a solution to your question on GIS Stack Exchange.

0 Kudos