Copy extent to clipboard

898
2
03-24-2017 03:01 AM
AndreasRondorf
New Contributor II

I am not a developer, but I want to use a python script from a former colleague. Parts of the script clip the current extent in ArcMap to the clipboard. It works well iwthhin in Addin on my Virtual Machine. If I use the same script/addin on my notebook (with a differnt user though) in the companies network, it doesn´t work. Any ideas? How do I have to modify the script?

import arcpy
import pythonaddins
from Tkinter import Tk
import os

...

class XY_Kopieren(object):
    """Implementation for ToeB_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        mxd = arcpy.mapping.MapDocument('current')
        activeDataFrame = mxd.activeView
        df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
        xmin = df.extent.XMin
        xmax = df.extent.XMax
        ymin = df.extent.YMin
        ymax = df.extent.YMax
        r = Tk()
        r.withdraw()
        r.clipboard_clear()
        r.clipboard_append(str(xmin)[0:6] + ',' + str(ymin)[0:7] + ',' + str(xmax)[0:6] + ',' + str(ymax)[0:7])
        r.destroy()
        pythonaddins.MessageBox('Die Koordinaten des aktuellen Raumausschnittes wurden in die Zwischenablage kopiert.', 'INFO', 0)
        pass

@Jake Skinner () published a similar Add-In called Extent Python Add-In. It works well my has blank spaces between the coordinates and decimals in it. I would need the coordinates copied like 334736,5658853,417290,57118 to the clipboard to use it in a second application. Can I change an Add-In? If not. Can you @jskinner_CountySandbox help?

#python #copy results to clipboard‌ #clipboard #copy extent
0 Kudos
2 Replies
NeilAyres
MVP Alum

If you can read the code you can always copy it and write roll your own...

As regards the formatting of the extent coords you could do something like this :

ExtStr = "{:.0f},{:.0f},{:.0f},{:.0f}".format(XMin, YMin, XMax, YMax)
0 Kudos
AndreasRondorf
New Contributor II

Thank you, Neil, for your help. Unfortunaltely I have not been able to try your ideas until today. I try to change immediately in the extent.esriaddin from @Jake Skinner.

I changed in the fileextent.esriaddin 

from


        extent = rectangle_geometry
        newExtent = str(round(extent.XMin, 2)) + ", " + str(round(extent.YMin, 2)) + ", " + str(round(extent.XMax, 2)) + ", " + str(round(extent.YMax, 2))
        w.OpenClipboard()
        w.EmptyClipboard()
        w.SetClipboardData(w.CF_TEXT, newExtent.rstrip())
        w.CloseClipboard()
        print newExtent
        ##pythonaddins.MessageBox(newExtent, 'Extent', 0)

 

to
        newExtent = str(round(extent.XMin)) + "," + str(round(extent.YMin)) + "," + str(round(extent.XMax)) + "," +

But I don´t get a change. The numbers in the clipboard have still two decimals and a blank space.

If I try to install the esriaddin once again not through the addin-manager but rather by by doubleclick I get a meaasage "unable to open file". Any idea

0 Kudos