-1

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)
  • 3
    Could you explain what do you mean by "doesn't work"? It works as expected for me. The fishnet layer remains in the TOC and is updated each time I select another layer in the drop-down list. Check under Geoprocesing > Geoprocessing Options that Overwrite the output of geoprocessing operations is enabled. This will let you overwrite the in_memory layer. A way to verify this causes any trouble is to delete the layer in the TOC and see if it will get re-created. – Alex Tereshenkov Mar 9 '15 at 9:57
  • Hi Thanks, after changing geoprocessing options, it is working fine. – Jaya Sudha Mar 9 '15 at 10:38
3

The fishnet layer will remain in the TOC and will be updated each time you select another layer in the drop-down list.

However, check under Geoprocesing > Geoprocessing Options that Overwrite the output of geoprocessing operations is enabled. This will let you overwrite the in_memory layer. A way to verify this causes any trouble is to delete the layer in the TOC and see if it will get re-created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.