Select to view content in your preferred language

Fnd the selected layer in the ArcMap Table Of Contents

1157
5
Jump to solution
05-09-2012 10:32 AM
PeterHewetson
Deactivated User
Is there an ArcPy equivalent to IMXDocument::SelectedItem to get the selected layer in the ArcMap Table of Contents?...

Dim pMxDoc As IMxDocument
Dim pLayer As ILayer

Set pMxDoc = ThisDocument
Set pLayer = pMxDoc.SelectedItem
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JasonScheirer
Esri Alum
0 Kudos
5 Replies
StephenKruzik
Deactivated User
now is this something where you know which layer is to be selected, or you're trying to figure it out?

If you already know the layers in the TofC, you can list them using the following in the python window

[HTML]mxd = arcpy.mapping.MapDocument("insert path to mxd here, or if within arcmap use "CURRENT" ")
arcpy.mapping.Listayers(mxd)[/HTML]

That will get you all of the layers in the TOC.  If it's more than that, then I don't think I'm quite clear on what you're looking for.  I'm not a VB guy, so I don't know what IMXDocument::SelectedItem actually means.
0 Kudos
PeterHewetson
Deactivated User
now is this something where you know which layer is to be selected, or you're trying to figure it out?

If you already know the layers in the TofC, you can list them using the following in the python window

[HTML]mxd = arcpy.mapping.MapDocument("insert path to mxd here, or if within arcmap use "CURRENT" ")
arcpy.mapping.Listayers(mxd)[/HTML]

That will get you all of the layers in the TOC.  If it's more than that, then I don't think I'm quite clear on what you're looking for.  I'm not a VB guy, so I don't know what IMXDocument::SelectedItem actually means.


Yes, that will return a list of all the map layers.  I was wondering if there was a way to reduce that list to just those layers selected by the user in the ArcMap TOC.  It would allow a quick method of inputing a particular layer(s) into a script.
0 Kudos
JasonScheirer
Esri Alum
Not in 10.0. In 10.1, you can use GetSelectedTOCLayerOrDataFrame.
0 Kudos
ThorstenDey
Occasional Contributor
This hint was very helpful.

But what kind of object is delivered by the "GetSelectedTOCLayerOrDataFrame-method"? I want to implement a new python addin, that applies a given symbology-file (lyr) to the selected layer in the TOC. I generated 3 lyr-files, one for each geometry-type (point, line, polygon), that hold all symbols of hundreds of shape-files in our system. And here is my question:
How can I get the geometry-type of the "GetSelectedTOCLayerOrDataFrame-object" in order to apply the right lyr-file.
Thanks in advance.
0 Kudos
JeffBarrette
Esri Regular Contributor
Have you tried arcpy.Describe?

The following was typed in the Python Window:

>>>mxd = arcpy.mapping.MapDocument("current")
>>>lyr = arcpy.mapping.ListLayers(mxd)[0]
>>> desc = arcpy.Describe(lyr)
>>> print desc.shapeType
Point

0 Kudos