<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Is &amp;quot;findAndReplaceWorkspacePath&amp;quot; unstable or is it me? in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/is-quot-findandreplaceworkspacepath-quot-unstable/m-p/324822#M3421</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;We have found that in some SDE scenarios that findAndReplaceWorkspacePath is not working, for example, going from a development database to a production database on the same server.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try using lyr.replaceDataSource instead.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We will update the Updating And Fixing Data Sources topic once we've completed our analysis.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 Sep 2011 13:50:42 GMT</pubDate>
    <dc:creator>JeffBarrette</dc:creator>
    <dc:date>2011-09-28T13:50:42Z</dc:date>
    <item>
      <title>Is "findAndReplaceWorkspacePath" unstable or is it me?</title>
      <link>https://community.esri.com/t5/mapping-questions/is-quot-findandreplaceworkspacepath-quot-unstable/m-p/324820#M3419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, after hours trying to figure out what's going on with the "findAndReplaceWorkspacePath" I'm just giving up and reaching out for help. So far, I am thinking that this method provides completely unexpected/unstable/unreliable results. But before I get to far with my frustrations, I need somebody to review this code and let me know what I am doing wrong. The problem is that the workspace path of the layer files don't get re-pointed to the new SDE connection file, whether I use validate = True or False. When set to True the script crashes miserably, even though the connection file/parameters is valid, so it this example I set it to False, which you would expect to work, but it does not! This scripts loops through a root folder, recursively finds all the ".lyr" file under the root and re-points the workspacePath location. It can be executed in PythonWin/Idle or the ArcMap Python window, the results are the same i.e. unexpected/unstable/unreliable i.e. the layers don't get re-pointed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, sys, os, traceback, time, sys, random, string
root = r"D:\eaub490\repath_layers\DNR Map Layers\Forest Management"

for path, folders, fileList in os.walk(root):
 print "*************\nFolder: " + path + "\n*************"
 for f in fileList:
&amp;nbsp; print f
&amp;nbsp; if f.endswith(".lyr"):
&amp;nbsp;&amp;nbsp; lyr = arcpy.mapping.Layer(path + "\\" + f)
&amp;nbsp;&amp;nbsp; if lyr.isGroupLayer == False:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("WORKSPACEPATH"):&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ".sde" in lyr.workspacePath:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; workPath = lyr.workspacePath
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print " * Old:", workPath
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isFeatureLayer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; workPathNew = r"D:\eaub490\repath_layers\sde_connections_read\ropa_v10.sde"&amp;nbsp; # this is a valid connection file
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.findAndReplaceWorkspacePath("", workPathNew, False)&amp;nbsp; # when validate = True then it becomes extremely unstable and unpredictable
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; workPathNew = r"D:\eaub490\repath_layers\sde_connections_read\raster_v10.sde"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.findAndReplaceWorkspacePath("", workPathNew, False)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.visible = False&amp;nbsp; # turn the visibility off
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.save()&amp;nbsp; # save to v.10
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.workspacePath &amp;lt;&amp;gt; workPathNew:&amp;nbsp; # check because the findAndReplaceWorkspacePath does not always works
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print " * Dang! the findAndReplaceWorkspacePath does not work:", lyr.workspacePath
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print " * New:", lyr.workspacePath
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print " * Not a SDE layer"
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print " * Workspacepath not supported"
&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print " * Group layer, cannot be re-pathed"&amp;nbsp; # as far as I know
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp; print " * Not a layer file"
 
print "\nEnd of program\n"
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:24:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/is-quot-findandreplaceworkspacepath-quot-unstable/m-p/324820#M3419</guid>
      <dc:creator>EricAubert</dc:creator>
      <dc:date>2021-12-11T15:24:10Z</dc:date>
    </item>
    <item>
      <title>Re: Is "findAndReplaceWorkspacePath" unstable or is it me?</title>
      <link>https://community.esri.com/t5/mapping-questions/is-quot-findandreplaceworkspacepath-quot-unstable/m-p/324821#M3420</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I was having the same problem executing this function as well.&amp;nbsp; I was also trying to set my new path to an SDE database.&amp;nbsp; It appeared to run, but after showing the hour glass for a while there would be no change.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just executed a test using this function from one file geodatabase to another (same database name, but in a new location) and it worked like a charm.&amp;nbsp; Maybe it is only good for the latter scenario.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Sep 2011 18:08:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/is-quot-findandreplaceworkspacepath-quot-unstable/m-p/324821#M3420</guid>
      <dc:creator>KristinGoff</dc:creator>
      <dc:date>2011-09-27T18:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: Is "findAndReplaceWorkspacePath" unstable or is it me?</title>
      <link>https://community.esri.com/t5/mapping-questions/is-quot-findandreplaceworkspacepath-quot-unstable/m-p/324822#M3421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;We have found that in some SDE scenarios that findAndReplaceWorkspacePath is not working, for example, going from a development database to a production database on the same server.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try using lyr.replaceDataSource instead.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;We will update the Updating And Fixing Data Sources topic once we've completed our analysis.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Sep 2011 13:50:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/is-quot-findandreplaceworkspacepath-quot-unstable/m-p/324822#M3421</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2011-09-28T13:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Is "findAndReplaceWorkspacePath" unstable or is it me?</title>
      <link>https://community.esri.com/t5/mapping-questions/is-quot-findandreplaceworkspacepath-quot-unstable/m-p/324823#M3422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I could never get findAndReplaceWorkspacePath to work either. But I did find more success with replaceDataSource when working with SDE data. Here is the syntax I used:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;lyr.replaceDataSource(r"Database Connections\&amp;lt;sde connection&amp;gt;.sde", "SDE_WORKSPACE", True)&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I used this to repoint the layers in map documents in ArcMap and in folders in ArcCatalog.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Oct 2012 19:37:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/is-quot-findandreplaceworkspacepath-quot-unstable/m-p/324823#M3422</guid>
      <dc:creator>WaiChan1</dc:creator>
      <dc:date>2012-10-05T19:37:34Z</dc:date>
    </item>
  </channel>
</rss>

