Hi All,
I have an MXD which contains a large number of layers that originally all linked to featureclasses within a single file geodatabase. I have since needed to move some of the data into another file geodatabase. My thinking was that after I moved the data I could use arcpy to iterate the layers, pick up any with broken sources and change their data source to target the new geodatabase. I have the code below which I adapted from HERE to suit my needs but it throws the error below below in red. I'm sure it is something simple but can anyone tell me what I am doing wrong here? The name printed by line 7 (i.e. State Electorates) is that or a featureclass so i don't see why it wouldn't work?
Many thanks in advance.
Gino
<SPAN class="keyword token">import</SPAN> arcpy
mxd <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>MapDocument<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"E:\_GINO's\Planning Geodatabase\Planning Geodatabases\Internal Geodatabase\Copy_of_Internal_Geodatabase_ArcGIS10.3(1).mxd"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> lyr <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>mxd<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> lyr<SPAN class="punctuation token">.</SPAN>supports<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"DATASOURCE"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> lyr<SPAN class="punctuation token">.</SPAN>isBroken<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="string token">"DYNAMIC_DATA.gdb"</SPAN> <SPAN class="keyword token">in</SPAN> lyr<SPAN class="punctuation token">.</SPAN>dataSource<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> lyr<SPAN class="punctuation token">.</SPAN>name
lyr<SPAN class="punctuation token">.</SPAN>findAndReplaceWorkspacePath<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">.</SPAN>workspacePath<SPAN class="punctuation token">,</SPAN> r<SPAN class="string token">"E:\_GINO's\Planning Geodatabase\Planning Geodatabases\Internal Geodatabase\STAND_ALONE_DATA.gdb"</SPAN><SPAN class="punctuation token">)</SPAN>
mxd<SPAN class="punctuation token">.</SPAN>saveACopy<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"E:\_GINO's\Planning Geodatabase\Planning Geodatabases\Internal Geodatabase\Updated_Internal_Geodatabase_ArcGIS10.3.mxd"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">del</SPAN> mxd<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
>>>
State Electorates
Traceback (most recent call last):
File "E:\_GINO's\Planning Geodatabase\Geodatabase Management\Script\updateDS.py", line 8, in <module>
lyr.findAndReplaceWorkspacePath(lyr.workspacePath, r"E:\_GINO's\Planning Geodatabase\Planning Geodatabases\Internal Geodatabase\STAND_ALONE_DATA.gdb")
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "C:\Program Files (x86)\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
>>>