2

I am creating a Python addin button and I would like to reference the path to the layer that is currently in an edit session to the code in the addin button. This way users will be able to use the functionality of the addin in button with a variety of different named layers that have attribute tables with the same headers.

My button currently uses this code.

inFeatures="m8010_seginit_061213"
fieldName="LFM"
expression=3000
arcpy.CalculateField_management(inFeatures, fieldName, expression, "PYTHON")

I would like to have "inFeatures="CURRENT"" or the path to the current layer is that is open in an edit session.

3

My work around to this problem was to use the combo box function available for these ESRI Addin toolbars. I then selected a layer from the combo box to reference in my buttons. I was not able however to specifically reference a the file in edit mode.

class ListLayers(object):
    """Implementation for NEZ_EDITS_addin.list_layers (ComboBox)"""
    def __init__(self):
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWWWWWWWW'
        self.width = 'WWWWWWWWWWW'
    def onSelChange(self, selection):
        global selected_layer
        selected_layer=arcpy.mapping.ListLayers(self.mxd, selection)[0]
        arcpy.RefreshActiveView()

    def onFocus(self, focused):
        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)

Key to this code was making sure that I made "selected_layer" a global variable so it can be referenced in the other classes/buttons. So now inFeatures is equal to the variable selected layer.

inFeatures = selected_layer
fieldName = "LFM"
expression = 3000
arcpy.CalculateField_management(inFeatures, fieldName, expression, "PYTHON")

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.