I'm trying to use the findAndReplaceWorkspacePath function and I'm getting an error in the utils.py & _mapping.py modules.
Here's the line from _mapping.py w the error (696) return convertArcObjectToPythonObject(self._arc_object.findAndReplaceWorkspacePath(*gp_fixargs((find_workspace_path, replace_workspace_path, validate), True)))
I'm using PyScripter3.2.2.0, Windows 7, ArcGIS 10.4.1. I just tried updating to the newest version of Python and that didn't do anything; same error.
My code is very basic. I'm a python beginner, looking to update a series of .lyr files. I'm working off of code from someone else that initially pulled in .lyr file paths from a text file, but I scaled it back to test on a single .lyr file first.
import sys, string, os, arcpy
new_wp = r" < new path > "
layer_file = r" < file path > "
lyrFile = arcpy.mapping.Layer(layer_file)
old_wp = lyrFile.workspacePath
lyrFile.findAndReplaceWorkspacePath(old_wp,new_wp)
lyrFile.save()
Throw print statements in, it is difficult to see what the problem is unless the results up to the point of failure are known
I added these lines just before the findAndReplaceWorkspacePath call and everything looked as expected.
print layer_file
print lyrFile
print old_wp
I did see this expanded error messaging though, which I had missed before. But, it doesn't really tell me anything.
Traceback (most recent call last):
File " < file path >", line 19, in <module>
lyrFile.findAndReplaceWorkspacePath(old_wp,new_wp)
File "C:\Program Files\ArcGIS\Desktop10.4\ArcPy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "C:\Program Files\ArcGIS\Desktop10.4\ArcPy\arcpy\_mapping.py", line 696, in findAndReplaceWorkspacePath
return convertArcObjectToPythonObject(self._arc_object.findAndReplaceWorkspacePath(*gp_fixargs((find_workspace_path, replace_workspace_path, validate), True)))
ValueError: Layer: Unexpected error
there is an error in the path(s)
Could you share the results of the print statement
print layer_file
print lyrFile
print old_wp
K:\ < folders >\CensusTracts1980.lyr
Census Tracts - 1980
C:\Documents and Settings\ < user >\Application Data\ESRI\ArcCatalog\SDE_Reader@5151@DPH-GIS-Central.sde
There are spaces in the folder names of the layer_file path, would that matter?
Thanks for taking a look!
spaces and the every funky @ and - really mess things up when you don't want them.
Work local... work in simple paths ... that should be your first course of debugging if you are working with anything network housed.
And the 'user' folder! stay clear of working there... make a folder on the c drive specific to your gis work.
This can definitely be arranged even in a networked and/or teaching environment, we forbid saving work to the old Docu...blah blah folder in our teaching labs because of the problems it can cause.
Sounds good, thanks.