# Business logic to implement the ComboBox def __init__(self): self.editable = True self.enabled = True def onSelChange(self, selection): # When a new layer is selected, create a new fishnet using the extent of layer. layer = arcpy.mapping.ListLayers(self.mxd, selection)[0] desc = arcpy.Describe(layer.dataSource) extent = desc.Extent fishnet = arcpy.CreateFishnet_management(r'in_memory\fishnet', '%f %f' %(extent.XMin, extent.YMin), '%f %f' %(extent.XMin, extent.YMax), 0, 0, 10, 10, '%f %f' %(extent.XMax, extent.YMax), 'NO_LABELS', '%f %f %f %f' %(extent.XMin, extent.YMin, extent.XMax, extent.YMax), 'POLYGON') arcpy.RefreshActiveView() 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)
class MyComboBox(object): """Implementation for MyComboBox""" def __init__(self): self.editable = True self.enabled = True self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): """Occurs when the user makes a selection from the ComboBox drop-down menu""" pass def onEditChange(self, text): """Occurs when the user manually enters text into the ComboBox""" pass def onFocus(self, focused): """Occurs when the user clicks on the Combobox, giving the ComboBox focus""" pass def onEnter(self): """Occurs when the user presses the 'Enter' key while the ComboBox has focus""" pass def refresh(self): """Occurs after a value is established within the ComboBox""" self.refresh()
def onFocus(self, focused): """Occurs when the user clicks on the Combobox, giving the ComboBox focus""" # Empty the Combobox items list self.items = [] # Establish a reference to the current MXD mxd = arcpy.mapping.MapDocument("Current") # Establish a reference to the first DataFrame object in the current MXD df = arcpy.mapping.ListDataFrames(mxd)[0] # Build a List of LayerObjects contained in the first DataFrame of the current MXD Layers = arcpy.mapping.ListLayers(mxd, "*", df) # Iterate through the Layers for Layer in LayerList: # Append the current Layer's name to the Items List self.items.append(Layer.name)
def onSelChange(self, selection): # Because 'mxd' and 'df' weren't given global scope, we have to reestablish them # in order to use them in this method mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDaaFrames(mxd)[0] # Reference the first Layer in the DataFrame of the MXD which has a name that matches # the current selection layer = arcpy.mapping.ListLayers(self.mxd, selection, df)[0] desc = arcpy.Describe(layer.dataSource) extent = desc.Extent fishnet = arcpy.CreateFishnet_management(r'in_memory\fishnet', '%f %f' %(extent.XMin, extent.YMin), '%f %f' %(extent.XMin, extent.YMax), 0, 0, 10, 10, '%f %f' %(extent.XMax, extent.YMax), 'NO_LABELS', '%f %f %f %f' %(extent.XMin, extent.YMin, extent.XMax, extent.YMax), 'POLYGON') arcpy.RefreshActiveView()
import arcpy import pythonaddins class FishnetComboBoxClass1(object): """Implementation for Comboboxfishnet_addin.combobox (ComboBox)""" def __init__(self): self.editable = True self.enabled = True self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): # Because 'mxd' and 'df' weren't given global scope, we have to reestablish them # in order to use them in this method mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDaaFrames(mxd)[0] # Reference the first Layer in the DataFrame of the MXD which has a name that matches # the current selection layer = arcpy.mapping.ListLayers(self.mxd, selection, df)[0] desc = arcpy.Describe(layer.dataSource) extent = desc.Extent fishnet = arcpy.CreateFishnet_management(r'in_memory\fishnet', '%f %f' %(extent.XMin, extent.YMin), '%f %f' %(extent.XMin, extent.YMax), 0, 0, 10, 10, '%f %f' %(extent.XMax, extent.YMax), 'NO_LABELS', '%f %f %f %f' %(extent.XMin, extent.YMin, extent.XMax, extent.YMax), 'POLYGON') def onEditChange(self, text): """Occurs when the user manually enters text into the ComboBox""" pass def onFocus(self, focused): """Occurs when the user clicks on the Combobox, giving the ComboBox focus""" # Empty the Combobox items list self.items = [] # Establish a reference to the current MXD mxd = arcpy.mapping.MapDocument("Current") # Establish a reference to the first DataFrame object in the current MXD df = arcpy.mapping.ListDataFrames(mxd)[0] # Build a List of LayerObjects contained in the first DataFrame of the current MXD Layers = arcpy.mapping.ListLayers(mxd, "*", df) # Iterate through the Layers for Layer in LayerList: # Append the current Layer's name to the Items List self.items.append(Layer.name) def onEnter(self): """Occurs when the user presses the 'Enter' key while the ComboBox has focus""" pass def refresh(self): """Occurs after a value is established within the ComboBox""" self.refresh()
def onFocus(self, focused): """Occurs when the user clicks on the Combobox, giving the ComboBox focus""" # Empty the Combobox items list self.items = [] # Establish a reference to the current MXD mxd = arcpy.mapping.MapDocument("Current") # Establish a reference to the first DataFrame object in the current MXD df = arcpy.mapping.ListDataFrames(mxd)[0] # Build a List of LayerObjects contained in the first DataFrame of the current MXD Layers = arcpy.mapping.ListLayers(mxd, "*", df) # Iterate through the Layers for Layer in Layers: # Append the current Layer's name to the Items List self.items.append(Layer.name)
It looks like you may have an issue in the onFocus method. You create a list of the current layers in the dataframe called "Layers" but then try to iterate though them with for Layer in LayerList. Try changing LayerList to Layers.
import arcpy import pythonaddins class FishnetComboBoxClass1(object): """Implementation for Comboboxfishnet_addin.combobox (ComboBox)""" def __init__(self): self.editable = True self.enabled = True self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): mxd = arcpy.mapping.MapDocument("Current") df = arcpy.mapping.ListDaaFrames(mxd)[0] layer = arcpy.mapping.ListLayers(self.mxd, selection, df)[0] desc = arcpy.Describe(layer.dataSource) extent = desc.Extent fishnet = arcpy.CreateFishnet_management(r'in_memory\fishnet', '%f %f' %(extent.XMin, extent.YMin), '%f %f' %(extent.XMin, extent.YMax), 0, 0, 10, 10, '%f %f' %(extent.XMax, extent.YMax), 'NO_LABELS', '%f %f %f %f' %(extent.XMin, extent.YMin, extent.XMax, extent.YMax), 'POLYGON') arcpy.RefreshActiveView() def onEditChange(self, text): """Occurs when the user manually enters text into the ComboBox""" pass def onFocus(self, focused): """Occurs when the user clicks on the Combobox, giving the ComboBox focus""" self.items = [] # Establish a reference to the current MXD mxd = arcpy.mapping.MapDocument("Current") # Establish a reference to the first DataFrame object in the current MXD df = arcpy.mapping.ListDataFrames(mxd)[0] # Build a List of LayerObjects contained in the first DataFrame of the current MXD Layers = arcpy.mapping.ListLayers(mxd, "*", df) # Iterate through the Layers for Layer in Layers self.items.append(Layer.name) def onEnter(self): """Occurs when the user presses the 'Enter' key while the ComboBox has focus""" pass def refresh(self): """Occurs after a value is established within the ComboBox""" self.refresh()