Identify the selected layer in the TOC: 2 Questions

268
0
02-26-2024 05:25 AM
Labels (2)
RandyMcGregor_BMcD
New Contributor III

With arcpy, you can use 'GetParameter' instead of 'GetParamaterAsText' to set up inputs. I have a script that  has one input - a layer selected by the user.

I was hoping - by using GetParameter - I could update that selected layer directly, but nothing happens. (I suspect the action is happening in memory and not to the layer within the TOC?). In this case, I want to apply a definition query.

What I have to do is, even though the one argument returns a layer object, identify from map.layerList the selected layer than apply the definition query to that. That works, but It feels redundant. But lyr.definitionQuery does not work when applied directly to the user choice.

  1. My first question is, is this as designed or am I missing something?
  2. Second question - Is there a way to identify the specific selected layer, besides using the name of the layer? I'd like to have the tool work on a selected layer even when more than on layer has the same name. Is there a property that indicates the order of the layer? If so, I haven't found it. 
    • In the input drop-down, ArcPro adds ':#' when more than one layer has the same name. Is it possible to access this index?

RandyMcGregor_BMcD_0-1708953755857.png

Thank you,

Randy McGregor

0 Replies