I have a simple add-in script for Arcmap 10.1 to create a toolbar, select a layer from a drop down list of the current layers in the project, buffer that layer four-miles, then use the resulting four-mile buffer output as an input for a six-mile outside buffer. I have a work flow where I repeatedly need to create a four-mile buffer with a six-mile outside buffer surrounding this. Everything functions up to and including the four-mile buffer layer creation, but I get no six-mile outside buffer being created. I have been working with ESRI support but having trouble resolving this. Any ideas?
import arcpy
import pythonaddins
import os
class ComboBoxClass1(object):
"""Implementation for DataRequestBuffer_addin.combobox (ComboBox)"""
def __init__(self):
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWWWWWWWWWWWW'
self.width = 'WWWWWWWWWWWWWWWWWWWW'
def onSelChange(self, selection):
arcpy.env.overwriteOutput = True
# When a new layer is selected, create a 4 mile buffer around that layer then create a 6 mile buffer surrounding the outside of the 4 mile buffer.
layer = arcpy.mapping.ListLayers(self.mxd, selection)[0]
outPath = os.path.dirname(layer.dataSource)
print outPath
# Buffer 4 miles
print 'Buffering %s with 4 mile buffer' % layer
arcpy.Buffer_analysis(layer, outPath + os.sep + str(layer) + "_4milebuff", "4 Miles", "FULL", "ROUND", "ALL", "")
buff6 = outPath + os.sep + str(layer) + "_4milebuff"
# Buffer 6 miles surrounding outside of 4 mile buffer
print 'Buffering %s with 6 mile outside buffer' % buff6
arcpy.Buffer_analysis(buff6, outPath + os.sep + str(layer) + "_6milebuffoutside", "6 Miles", "OUTSIDE_ONLY", "ROUND", "ALL", "")
arcpy.RefreshActiveView()
def onEditChange(self, text):
pass
def onFocus(self, focused):
# When the combo box has focus, update the combo box with the list of layer names.
if focused:
self.mxd = arcpy.mapping.MapDocument('current')
layers = arcpy.mapping.ListLayers(self.mxd)
self.items = []
for layer in layers:
self.items.append(layer.name)
def onEnter(self):
pass
def refresh(self):
pass
-
3Does the output data source already exist? Does it get to the print statement before the buffer call? Can you put one after the 6 mile buffer runs too to confirm the tool ran? Maybe use the result object it returns and print out what GetMessages says? Does an exception show up in the Python window?Jason Scheirer– Jason Scheirer2012年09月21日 20:52:41 +00:00Commented Sep 21, 2012 at 20:52
1 Answer 1
The following worked for a file geodatabase but not for a shapefile, now working to get it to work with a shapefile. Suspect a naming convention. The geoprocessing is working with a shapefile when I put the code in the python window and changed the output path to a set location for example: r"V:\ActiveProjects4円milebuff". So no exception in the Python window. Have not tried GetMessages yet. Got bogged down with other work. Will post results.
import arcpy
import pythonaddins
import os
class ComboBoxClass1(object):
"""Implementation for DataRequestBuffer_addin.combobox (ComboBox)"""
def __init__(self):
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWWWWWWWWWWWW'
self.width = 'WWWWWWWWWWWWWWWWWWWW'
def onSelChange(self, selection):
arcpy.env.overwriteOutput = True
# When a new layer is selected, create a 4 mile buffer around that layer then create a 6 mile buffer surrounding the outside of the 4 mile buffer.
layer = arcpy.mapping.ListLayers(self.mxd, selection)[0]
outPath = os.path.dirname(layer.dataSource)
print outPath
# Buffer 4 miles
print 'Buffering %s with 4 mile buffer' % layer
arcpy.Buffer_analysis(layer, outPath + os.sep + str(layer) + "_4milebuff", "4 Miles", "FULL", "ROUND", "ALL", "")
buff6 = outPath + os.sep + str(layer) + "_4milebuff"
# Buffer 6 miles surrounding outside of 4 mile buffer
print 'Buffering %s with 6 mile outside buffer' % buff6
arcpy.Buffer_analysis(buff6, outPath + os.sep + "_6milebuffoutside", "6 Miles", "OUTSIDE_ONLY", "ROUND", "ALL", "")
arcpy.RefreshActiveView()
def onEditChange(self, text):
pass
def onFocus(self, focused):
# When the combo box has focus, update the combo box with the list of layer names.
if focused:
self.mxd = arcpy.mapping.MapDocument('current')
layers = arcpy.mapping.ListLayers(self.mxd)
self.items = []
for layer in layers:
self.items.append(layer.name)
def onEnter(self):
pass
def refresh(self):
pass
Explore related questions
See similar questions with these tags.