soatley

addLayer error

Discussion created by soatley on Mar 3, 2011
Latest reply on Aug 5, 2011 by napugh
Hi Folks,

I'm trying to load some image layers to a dataframe. The file name / path of the image is read from a feature class using a search cursor.

...

ss = arcpy.SearchCursor("MyLayer", "", "", "FILENAME")
for s in ss:
    arcpy.AddMessage(s.FILENAME)
    addLayer = arcpy.mapping.Layer(s.FILENAME)
    arcpy.mapping.AddLayer(df, addLayer, "TOP")


The AddMessage works and shows the correct name, but I get the following error on the addLayer code:

<type 'exceptions.ValueError'>: Object: CreateObject Layer invalid data source


Is it possible that it's a path error? The value from the feature class is a Windows path so it contains \'s. I've post-processed the name to replace \'s with /'s, but that didn't make a difference.

I assume addLayer works with .sid, .tif, etc?

Thanks,
Scott

Outcomes