AnsweredAssumed Answered

Layer Invalid Data Source ?

Question asked by rangermry on Oct 10, 2013
Latest reply on Oct 11, 2013 by rangermry
I wrote a script tool where a map is generated, a checkbox of layers can be checked to add the layers to the map, and when I run it some layers will add to the new map and some layers, throw "Object: CreateObject Layer invalid data source." 

I did notice all of the layers that error have a space in their names.  They are valid layers as in when AddData is used manually they can add to a map.  I know the list of the layers is a Python multiValue list, not a Python list, taking out one if the items and testing it's type yields that the item is a unicode object.  I also noticed when I print the mutliValues out the ones with spaces have single quotes surrounding them and the ones w/o spaces do not have single quotes surrounding them...
'file path here' Object: CreateObject Layer invalid data source 'file path here' Object: CreateObject Layer invalid data source filePathHere Added: FilePath.lyr




I convert them to layers in the script when I iterate through the multiValue list like so:
try:     if countyLayers[0]:         for item in countyLayers.split(';'):             try:                 item1=arcpy.mapping.Layer(item)                 arcpy.mapping.AddLayer(dataFrame,item1,"AUTO_ARRANGE")                 item2=str(item.split("\\")[-1])                 arcpy.AddMessage("Added: " + item2)                 arcpy.RefreshTOC()                 del item1, item2             except Exception as e:                 arcpy.AddMessage(e.message)                 pass except:     arcpy.AddMessage("No county data specified to add")     pass

Outcomes