I'm using ArcGIS 10.3. I have an MXD that contains symbolized global raster images. I have a GP tool that masks these rasters to a country or state and exports the images. I'm trying to update the source background layers and rasters each time a new country is chosen. The layer names are all generic, but the source files all have the country or state name tagged on. findAndReplaceWorkspacePath works just fine with the background layers (shapefiles), but it won't update the rasters. I've confirmed the old and new sources with print statements, it's just not changing the source. The only time I get images is if I use the default state (Texas) set in the MXD. If I choose any other location, I just get a blank country or state outline image.
Here is my code snippet:
layer_list <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Precip"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"High_Temp"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Temp_Departure"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> filename <SPAN class="keyword token">in</SPAN> layer_list<SPAN class="punctuation token">:</SPAN>
layer_name <SPAN class="operator token">=</SPAN> filename
<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> layer_name <SPAN class="operator token">==</SPAN> str<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
old_source <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>dirname<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">.</SPAN>dataSource<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">##print old_source + "\\" + layer_name</SPAN>
new_source <SPAN class="operator token">=</SPAN> country_temp_path
<SPAN class="comment token">##print new_source + "\\" + layer_name</SPAN>
lyr<SPAN class="punctuation token">.</SPAN>findAndReplaceWorkspacePath<SPAN class="punctuation token">(</SPAN>old_source<SPAN class="punctuation token">,</SPAN> new_source<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>