Users here add a picture to a map using the 'add data'. Their first task is to right-click the jpg in the Table of Contents, select 'properties', select 'symbology' and then 'Classify' and then choose a new colors for the different ranges (to make the background transparent).

I can create a model to do this and, alternatively, can write a arcpy script to do this but in both cases, I have to hardcode the name of the input layer.

  • How do I use the selected layer in the TOC (i.e. clicked via the mouse and is now highlighted) as the input (and output) to my script?

Ideally, the user would add the picture, click on it to highlight it (in the TOC) and then hit a key combination to execute the script.

  • Eric - Did you ever find a way to do this with ArcPy methods? It doesn't seem like the MapDocument class has a SelectedItem property. Thanks, emeline
    – user25537
    Jan 7, 2014 at 14:56

1 Answer 1


You can find the selected layer in the ArcMap Table Of Contents using iMXDocument::SelectedItem

Here's a simple VBA snippet:

Dim pMxDoc As IMxDocument
Dim pLayer As ILayer

Set pMxDoc = ThisDocument
Set pLayer = pMxDoc.SelectedItem


  • You mentioned ArcPy - unfortunately I'm not sure how to do this in ArcPy, hence my ArcObjects-based answer. I hope it at least gives some pointers Sep 8, 2011 at 6:01
  • Thanks for your response, Stephen. Appreciate the help. If anyone else has an arcpy solution, I'd love to hear it.
    – Eric
    Sep 8, 2011 at 6:26
  • 1
    It's possible to access ArcObjects from within python, see: gis.stackexchange.com/questions/80/…
    – DPierce
    Jan 7, 2014 at 15:00

Your Answer

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

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