Whenever I attempt to use AddLayer it gives me: Runtime error <type 'exceptions.AssertionError'>

This is what I've been using:

arcpy.mapping.AddLayer(MainDF, r"\\GEOGDATA\campusmapping\CampusWide\LayerFiles\CAD\Floor2\Casanova2", "BOTTOM")

Casanova2 is a .lyr file. I've also attempted to use this with a few other layer files. Every time it gives me an AssertionError.

Do you know what I'm doing wrong?

  • Have you tried a local path instead of a network path? Sep 19, 2010 at 13:20

2 Answers 2


I figured out the problem. The second parameter needs to be a previously-defined layer, not a string that points to the layer.

addLayer = arcpy.mapping.Layer(r"\\GEOGDATA\campusmapping\CampusWide\LayerFiles\CAD\Floor2\Casanova2")
arcpy.mapping.AddLayer(MainDF, addLayer, "BOTTOM")

Works great.


Hard to say, but you could try following the sample in API documentation: AddLayer

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "New Data Frame")[0]
addLayer = arcpy.mapping.Layer(r"C:\Project\Data\Orthophoto.lyr")
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
del mxd, addLayer

Your Answer

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

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