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

I'm trying to pass an in memory layer object created from a feature class using Code:


into the Code:


function. It's erroring out, so I think it's having trouble with the in memory feature layer (Does a feature layer have a.lyr extension?).

My code is:


arcpy.MakeFeatureLayer_management("SOILFC", "soil.lyr")
arcpy.mapping.ExportReport("soil.lyr", reportfilename, r"C:\Test_Outputs\ProjectReport1.xls")

I'm not sure if the mapping class needs an actual map document to work on, but I'm hoping not. I don't want to go through the process of creating a temp .mxd, setting a dataframe reference and then add in some layers somewhere just for the purpose of getting a layer object to create a report. I was just hoping I could create the report using in memory objects because the only thing I care about if the .xls report from the final output.

share|improve this question
up vote 4 down vote accepted doesn't make a layer file, it makes a layer in memory. ExportReport requires a layer object. Combining the two, you can do this:

# Make the layer"SOILFC", "soil_layer")

# Get reference to layer
lyr = arcpy.mapping.Layer("soil_layer")

# Do the magic part
arcpy.mapping.ExportReport(lyr, reportfilename, r"C:\Test_Outputs\ProjectReport1.xls")

# Remove layer from TOC and memory
del lyr"soil_layer")

The missing part in your script is getting a layer object from the newly created Feature Layer.

share|improve this answer
Thanks Jason. This is exactly what I was looking for. I didn't realize I had to set the feature layer to a "mapping" layer. It makes sense now that I see it. – Mike Mar 5 '13 at 0:25

MakeFeatureLayer makes an in_memory layer. When using that tool you dont supply an extension. A layer with an extension of .lyr is a layerfile on disk. Typically a layer file on disk is a pointer to data with symbology set.

Anyways... to answer your question, you want an arcpy.mapping.Layer for use with the export tool

Try this....(assuming you have a .LYR already created)

soil = arcpy.mapping.Layer(r"c:\path\to\layerFile\soil.lyr")
arcpy.mapping.ExportReport(soil, reportfilename, r"C:\Test_Outputs\ProjectReport1.xls")
share|improve this answer
Thanks KHibma. I was trying to do all my back end processing in memory, without creating objects that will persist on disk afterwards (i.e. mxd's, layer files, etc) You solution would work well if I wanted to create layer files. Thanks for helping out. – Mike Mar 5 '13 at 0:28

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.