I have a working python script:
import arcpy
sdeconnection = arcpy.GetParameterAsText(0)
layerfiles = arcpy.GetParameterAsText(1).split(";")
for layerfile in layerfiles:
print layerfile
lyr = arcpy.mapping.Layer(layerfile)
lyr.replaceDataSource(sdeconnection, "SDE_WORKSPACE", lyr.datasetName, False)
lyr.save()
del lyr
I can run it from the command line with multiple layer files as input (separated by ";").
However I cannot make it work when I the script to add to a toolbox. The script runs as expected if I set "multivalue" to false for the layerfiles parameter.
However when I set "multivalue" to true I get the error:
Start Time: Thu May 16 10:13:47 2013
Running script changeLyrWorkspace...
<type 'exceptions.ValueError'>: Object: CreateObject Layer invalid data source
Failed to execute (changeLyrWorkspace).
Failed at Thu May 16 10:13:47 2013 (Elapsed Time: 0,00 seconds)
I get this error regardless of whether I add one or more layers when I run the script through the toolbox.
EDIT
It turns out that the script works through the GUI if there are no spaces in file name of the layer file.
Are there any workarounds for this problem?