Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to connect an existing .lyr file to a variable defined as lyr2.

lyr2 = arcpy.mapping.Layer(r"C:/Iso100Red.lyr")

Although its a .lyr file I´ll get this Errorcode:

Runtime error : Object: CreateObject Layer invalid data source

What could be the problem here?

share|improve this question
    
might be because '/' is not the valid path seperator for windows. You have to use '\', eg. "C:\Iso100Red.lyr". See here: en.wikipedia.org/wiki/Path_%28computing%29 –  Curlew Aug 7 '13 at 18:35
    
Forward slash is fine for Python on Windows. I thought using raw (r) with forward slash (it is designed to avoid backslash being treated as an escape character) may have been the problem but I just tested and it worked fine at ArcGIS 10.2 with Python 2.7.3. –  PolyGeo Aug 7 '13 at 22:20
    
The error message isn't even that cryptic. Is says Layer invalid data source. This means the layer data is not valid. That means that when attempting to open the .lyr file ArcGIS was either unable to access the file or the data within was not valid Layer information. –  Jason Scheirer Aug 7 '13 at 22:56
    
I created the file straight out of ArcGis.So the data within should be ok. –  gesi666 Aug 8 '13 at 12:46

1 Answer 1

The file C:\Iso100Red.lyr does not exist or isn't a valid layer file.

share|improve this answer

Your Answer

 
discard

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.