import arcpy import pythonaddins class SuperBuffer(object): """Implementation for LYR.THM_WkrsSqMi (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): #Instantiate 'mxd' and 'df' as the Map Document and DataFrame variables mxd = arcpy.mapping.MapDocument("Current") print "'mxd' instantiated as Map Document variable." df = arcpy.mapping.ListDataFrames(mxd) print "'df' instantiated as DataFrame variable." #Create a Variable for the Layer you wish to Buffer. Later, you can get this dynamically #by using the 'arcpy.mapping.ListLayers' function to populate a Combobox with the layers #in your TOC layer = arcpy.mapping.ListLayers(mxd, "Layer you want to Buffer", df) print "'layer' variable instantiated." #Create a Variable to hold your Output FC so that you can add it to the Map after it #is created by the buffer tool. out_fc ="Layer_Buffer" print "'out_fc' variable instantiated." #Establish your Workspace workspace = arcpy.env.workspace = "C:\Temp\MyFileGeodatabase.gdb" print "Workspace set." #Run the Buffer Analysis on your Layer. You could also specify the distance and unit #of measurement dynamically using Comboboxes for Each and use the 'selection' for #those Comboboxes as the input. print "Buffering Layer..." arcpy.Buffer_analysis(layer, workspace + "\"" + out_fc, "2 Miles", "FULL", "ROUND", "ALL") print "Buffer Operation Complete." #Add the newly created Buffer Layer to your MXD print "Adding Buffer to Map Document" arcpy.mapping.AddLayer(df, out_fc, "AUTO_ARRANGE") print "Script Complete"
Greetings, My assignment is to create a custom tool on the tool bar using a python script.
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.