In ArcObjects, it is possible to retrieve the currently selected editable layer using IEditor3.CurrentTemplate.Layer, or IEditLayers.CurrentLayer.

Is it possible to do the same thing in ArcPy?

In Python add-in extensions, there is an onCurrentLayerChanged method, but no corresponding property as far as I can tell to determine the current layer, which begs another question -- what is that method intended to be used for?


I think you are probably seeing the key difference between ArcPy and ArcObjects and later the Python Add-in.

Arcpy is designed to access the data itself, but doesn't have ties to the user interface. This is why, if you want to access a layer in the table of contents, you have to return the list of layers, then iterate through until you get to the one you want. From what I can tell, Arcpy doesn't know anything about a user interface. Even in the case of a selection of features, they are seen as an object collection, but there is no reference to how this selection may have been created.

On the other hand, ArcObjects, and now the Add-ins, have a definite tie-in to the user interface. As you listed with ArcObjects, the IEditLayers.CurrentLayer class sees that a user has selected a particular layer in the editor.

For the Python add-in, you found the onCurrentLayerchanged method, which returns when the layer has been changed.
If you look in the python addins module, there is a function for GetSelectedTOCLayerOrDataFrame. This would at least return what has been selected in the table of contents.
I think the way you would use these two methods is in combination. Knowing the selected layer to start with will let you perform actions based on that layer name, or feature type, etc. If you then are checking to see when the current layer changes during an edit session, you would be able to enable or disable tools, or raise warnings based on if said tools were relevant to the characteristics of the new layer that was selected.

  • I did notice the GetSelectedTOCLayerOrDataFrame method, however, that requires the user to select a layer in the TOC rather than the usual editing interface, and there is no guarantee that the selected TOC layer is an editable layer. Based on trawling around the ESRI forums, it does not appear there is a satisfactory solution at this time except to use ArcObjects. I hope to be proven wrong :) – blah238 Nov 18 '13 at 23:43
  • It kind of seems like there is a difference between ArcObjects and the add-in module. What layer does the arcobjects method return? Is it returning the layer that is selected in the Create Features dialog? That is the only place in the editor tools that you could select a layer now. Otherwise, once you start editing, you can simply grab any feature from any layer that you want to edit. There isn't a "Current" edit layer anymore. Are you looking for the currently selected Create Features layer? – Get Spatial Nov 19 '13 at 0:05
  • It is possible to use either the feature templates based editing mode introduced at 10.0 or the earlier "target layer" edit mode: help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… I believe the ArcObjects properties I mentioned correspond to the two modes but I'm not sure what they return if the opposite mode is enabled. – blah238 Nov 19 '13 at 0:17

As of 10.3, there are new attributes on the Extension object that may be of use to you: the Extension.currentLayer and Extension.editSelection properties.

  • Extension.currentLayer always appears to return None. – brian h wilson Apr 16 '18 at 23:11
  • When I come across things like this I conclude that good QC does not contribute to the bottom line at ESRI, so they just don't bother to do it. 3+ years and 3 more releases have gone by and it's still broken. – brian h wilson Apr 16 '18 at 23:25

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.