<?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: Python Find &amp; Replace WorkspacePaths in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-find-replace-workspacepaths/m-p/104035#M8015</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A couple things to check.&lt;/P&gt;&lt;P&gt;1) check to make sure the values of devconn1 and devconn2 are the exact same in both MXDs and match the variable (i.e. upper/lower case) &lt;/P&gt;&lt;P&gt;2) I had this problem with on and running MXD doctor fixed it&amp;nbsp; &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//000300000019000000" title="http://resources.arcgis.com/en/help/main/10.2/index.html#//000300000019000000"&gt;ArcGIS Help (10.2, 10.2.1, and 10.2.2)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I had an issue when trying to run my script thru ArcCatalog 10.2.x&amp;nbsp; on a mxd saved as 10.3.&amp;nbsp; (we have a mixed environment)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&amp;nbsp; I'm working on a similar project right now....but with many more broken links.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 May 2015 15:00:14 GMT</pubDate>
    <dc:creator>RebeccaStrauch__GISP</dc:creator>
    <dc:date>2015-05-28T15:00:14Z</dc:date>
    <item>
      <title>Python Find &amp; Replace WorkspacePaths</title>
      <link>https://community.esri.com/t5/python-questions/python-find-replace-workspacepaths/m-p/104034#M8014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have created a python script that lists all the mxds within a folder directory and then replaces the workspace paths. Now it works correctly for the majority of mxds but on a couple of the mxds it is failing to to replace the workspace path. I would appreciate any advice. I have copied the code into this question but also attached the code. Please note I have more than 1 database connection hence why there is the two find and replace lines for the two connections.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# ##Lists all MXDs within a folder and replaces the SDE connection&lt;/P&gt;&lt;P&gt;for fileName in os.listdir(path):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(path, fileName)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullPath):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, extension = os.path.splitext(fullPath)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extension.lower() == ".mxd":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullPath)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(devconn1, conn1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.findAndReplaceWorkspacePaths(devconn2, conn2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.saveACopy(os.path.join(output, fileName))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 14:49:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-find-replace-workspacepaths/m-p/104034#M8014</guid>
      <dc:creator>JohnByrne</dc:creator>
      <dc:date>2015-05-28T14:49:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python Find &amp; Replace WorkspacePaths</title>
      <link>https://community.esri.com/t5/python-questions/python-find-replace-workspacepaths/m-p/104035#M8015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A couple things to check.&lt;/P&gt;&lt;P&gt;1) check to make sure the values of devconn1 and devconn2 are the exact same in both MXDs and match the variable (i.e. upper/lower case) &lt;/P&gt;&lt;P&gt;2) I had this problem with on and running MXD doctor fixed it&amp;nbsp; &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//000300000019000000" title="http://resources.arcgis.com/en/help/main/10.2/index.html#//000300000019000000"&gt;ArcGIS Help (10.2, 10.2.1, and 10.2.2)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I had an issue when trying to run my script thru ArcCatalog 10.2.x&amp;nbsp; on a mxd saved as 10.3.&amp;nbsp; (we have a mixed environment)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&amp;nbsp; I'm working on a similar project right now....but with many more broken links.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 15:00:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-find-replace-workspacepaths/m-p/104035#M8015</guid>
      <dc:creator>RebeccaStrauch__GISP</dc:creator>
      <dc:date>2015-05-28T15:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python Find &amp; Replace WorkspacePaths</title>
      <link>https://community.esri.com/t5/python-questions/python-find-replace-workspacepaths/m-p/104036#M8016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If the new data sources are SDE databases, I have had better luck updating each individual layers using replaceDataSource.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a sample:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for fileName in os.listdir(path):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fullPath = os.path.join(path, fileName)
&amp;nbsp;&amp;nbsp;&amp;nbsp; if os.path.isfile(fullPath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basename, extension = os.path.splitext(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if extension.lower() == ".mxd":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(fullPath)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("DATASOURCE"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #add some code here to check if the old database is being used

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #update the layer datasource if necessary
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.replaceDataSource(newSdeCnctPath, "SDE_WORKSPACE", newDataLayerName, False)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.saveACopy(os.path.join(output, fileName))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:22:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-find-replace-workspacepaths/m-p/104036#M8016</guid>
      <dc:creator>BillDaigle</dc:creator>
      <dc:date>2021-12-11T06:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python Find &amp; Replace WorkspacePaths</title>
      <link>https://community.esri.com/t5/python-questions/python-find-replace-workspacepaths/m-p/104037#M8017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rebecca - Yeah I made all though checks and they were ok. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bill - your solution worked perfectly until I had an mxd that had more than one database connection in there e.g: DARDOFMD@lpisapp.sde &amp;amp; DARDOFMD@suppapp.sde.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I get an mxd with only some of the layers replaced and others with broken links!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So close...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 May 2015 16:38:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-find-replace-workspacepaths/m-p/104037#M8017</guid>
      <dc:creator>JohnByrne</dc:creator>
      <dc:date>2015-05-28T16:38:04Z</dc:date>
    </item>
  </channel>
</rss>

