Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What the code does successfully so far, is gets a list of the layers in the first data frame of the current map. What it doesn't succeed in doing is, joining the layer names to the gdb location using os.path.join(), so I can then do a clip against an existing feature class.

I think I need to convert the lyr names to a string before I can use it in a Clip_analysis, how do I do that?

Here is what I've got so far:

import arcpy
import arcpy.mapping
import os

#Set the current map
mxd = arcpy.mapping.MapDocument("CURRENT")

# Set the dataframe
df = arcpy.mapping.ListDataFrames(mxd)[0]

# Get list of Layers from toc
layers = arcpy.mapping.ListLayers(mxd,"",df)

#Set the output workspace
outWorkspace = r'C:\Users\jsommerville\Documents\ArcGIS\California\ProjectData.gdb'

for lyr in layers: 
    outFeatureClass = os.path.join(outWorkspace, lyr) 
    arcpy.Clip_analysis(lyr, "extent", outFeatureClass)

The error message I'm getting: 'Layer' object is not subscriptable

share|improve this question

You are correct about needing to convert the layer name to a string. You can get the layer name as a string by calling The reason for this is each layer is a layer object, which won't work in os.path.join(). However, the object has a 'name' property that you can set or pass to other string functions. To use it, call os.path.join(outWorkspace,

share|improve this answer
Thanks Jay, you rock! – Jon Mar 28 '13 at 20:26
If this answer worked for you, please mark it as the accepted answer. Thanks! – blord-castillo Mar 29 '13 at 17:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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