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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 20, 2013 at 23:09

1 Answer 1

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")
Jason Scheirer
18k2 gold badges55 silver badges72 bronze badges
answered Nov 8, 2013 at 14:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.