Python add-in works once only?

المشرف العام

Administrator
طاقم الإدارة
There is a sample in ArcGIS 10.1 help on creating a add-in using python. This works only once when a layer is selected in combobox, if i need to use this functionality again it does not work and i need to restart arcmap again, then it works.

# 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)

أكثر...
 
أعلى