<?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: Using arcpy.mapping to change the datasource for .mxd? in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56639#M303</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the input, I do use the del mxd at the end of the script. The lock I'm referring to appears in both the original and new datasource (&amp;nbsp;both File GDB's) whenever you re-open the new mxd created by the saveACopy or same thing happens if I use just save().&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 May 2018 21:31:20 GMT</pubDate>
    <dc:creator>DarylHochhalter</dc:creator>
    <dc:date>2018-05-31T21:31:20Z</dc:date>
    <item>
      <title>Using arcpy.mapping to change the datasource for .mxd?</title>
      <link>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56637#M301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have successfully changed the data sources for the map documents (.mxd) files, but find that when I open the mxd it puts a lock on both the old and new file GDB. I can't find anything in the updated mxd that references the old file GDB but there must be something left.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;CurFldr = r'\\Gis Server Data\Replicas\test' + '\\'&lt;BR /&gt;OldGDB = arcpy.GetParameterAsText(0)&lt;BR /&gt;NewGDB = arcpy.GetParameterAsText(1)&lt;BR /&gt;mxd = arcpy.mapping.MapDocument(r'\\Gis Server Data\Replicas\test\test.mxd')&lt;BR /&gt;mxd.findAndReplaceWorkspacePaths(CurFldr + OldGDB, CurFldr + NewGDB)&lt;BR /&gt;mxd.saveACopy(r'\\Gis Server Data\Replicas\test\Copy_of_test.mxd')&lt;BR /&gt;del mxd&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have also tried&amp;nbsp;&lt;SPAN class="" style="color: #4d4d4d;"&gt;mxd&lt;/SPAN&gt;&lt;SPAN class="" style="color: #4d4d4d;"&gt;.&lt;/SPAN&gt;&lt;SPAN class="" style="color: #4d4d4d;"&gt;replaceWorkspaces &amp;amp; mxd.save()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="" style="color: #4d4d4d;"&gt;Using the buildt-in set datasource tool seems to work fine on the same mxd files.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="" style="color: #4d4d4d;"&gt;Any ideas would be appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="" style="color: #4d4d4d;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2018 20:50:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56637#M301</guid>
      <dc:creator>DarylHochhalter</dc:creator>
      <dc:date>2018-05-31T20:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using arcpy.mapping to change the datasource for .mxd?</title>
      <link>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56638#M302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;strange according to&lt;STRONG&gt;&amp;nbsp;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/mapdocument-class.htm"&gt;mapdocument-class&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #4d4d4d; font-family: 'Lucida Grande','Segoe UI','Arial',sans-serif; font-size: 13.93px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 23.82px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;The variable that references the MapDocument object will place a lock on the map document file. It is good practice to remove the Map Document object reference using the Python &lt;/SPAN&gt;&lt;SPAN style="background-color: transparent; color: #4d4d4d; font-family: &amp;amp;quot; consolas&amp;amp;quot;,&amp;amp;quot;andale mono&amp;amp;quot;,&amp;amp;quot;lucida console&amp;amp;quot;,&amp;amp;quot;monaco&amp;amp;quot;,&amp;amp;quot;courier new&amp;amp;quot;,courier,monospace; font-size: 13.93px; font-style: normal; font-variant: normal; font-weight: bold; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;del&lt;/SPAN&gt;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #4d4d4d; font-family: 'Lucida Grande','Segoe UI','Arial',sans-serif; font-size: 13.93px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 23.82px; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt; command at the end of a script or within a try/except statement.&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But find and replace approaches as outlined in&amp;nbsp;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/updatingandfixingdatasources.htm"&gt;updating and fixing datasources&lt;/A&gt; don't mention locks.&lt;/P&gt;&lt;P&gt;Perhaps the lock exists in the source and is being persisted in the copy.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But then again you are on ....&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #3d3d3d; font-family: arial,helvetica,'helvetica neue',verdana,sans-serif; font-size: 15px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px; word-wrap: break-word;"&gt;r'\\Gis Server Data\Replicas\test\test.mxd&lt;/SPAN&gt; ... which pretty well rules out a normal folder/file relationship.&amp;nbsp; Sadly copying the project and the data to a local drive to fix the issue would be a long way around to fix the problem&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2018 21:23:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56638#M302</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-05-31T21:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using arcpy.mapping to change the datasource for .mxd?</title>
      <link>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56639#M303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the input, I do use the del mxd at the end of the script. The lock I'm referring to appears in both the original and new datasource (&amp;nbsp;both File GDB's) whenever you re-open the new mxd created by the saveACopy or same thing happens if I use just save().&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2018 21:31:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56639#M303</guid>
      <dc:creator>DarylHochhalter</dc:creator>
      <dc:date>2018-05-31T21:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using arcpy.mapping to change the datasource for .mxd?</title>
      <link>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56640#M304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Daryl, I saw the del, but the only way it appears that you are going to get rid of the lock is to get rid of the lock in the original.&amp;nbsp; There must be something... but it may lie with where your project and data are located.&amp;nbsp; On a local drive with full administrative rights, there are ways to remove the lock files&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2018 21:37:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56640#M304</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-05-31T21:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using arcpy.mapping to change the datasource for .mxd?</title>
      <link>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56641#M305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I close the arcmap, both locks go away. If I reopen the mxd, both locks reappear, so yes for some reason the script is keeping some reference to the datasource in the original mxd&amp;nbsp;even though all the layers now reference the new datasource.&lt;/P&gt;&lt;P&gt;It is something in the script, because if I use the built-in set datasource tool to change the source and save a copy from the same original mxd, the problem with the locks in both File GDB's isn't there when I reopen the resulting mxd.&lt;/P&gt;&lt;P&gt;I'm working on it right now, and may have just found the fix, need to test one more time. The&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;mxd.findAndReplaceWorkspacePaths call uses true for the default validate input. I just ran it adding False and it appears to have solved the issue, but going to repeat that one more time.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2018 21:47:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56641#M305</guid>
      <dc:creator>DarylHochhalter</dc:creator>
      <dc:date>2018-05-31T21:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using arcpy.mapping to change the datasource for .mxd?</title>
      <link>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56642#M306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is indeed the issue, using False for the validate parameter is a must, if you don't the resulting mxd still references the the original datasource in some way. I just ran it both ways twice and got the same results.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff;"&gt;import arcpy&lt;/SPAN&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;SPAN style="background-color: #ffffff;"&gt;CurFldr = r'\\Gis Server Data\Replicas\test' + '\\'&lt;/SPAN&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;SPAN style="background-color: #ffffff;"&gt;OldGDB = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;SPAN style="background-color: #ffffff;"&gt;NewGDB = arcpy.GetParameterAsText(1)&lt;/SPAN&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;SPAN style="background-color: #ffffff;"&gt;mxd = arcpy.mapping.MapDocument(r'\\Gis Server Data\Replicas\test\test.mxd')&lt;/SPAN&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;SPAN style="background-color: #ffffff;"&gt;mxd.findAndReplaceWorkspacePaths(CurFldr + OldGDB, CurFldr + NewGDB&lt;STRONG&gt;, False&lt;/STRONG&gt;)&lt;/SPAN&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;SPAN style="background-color: #ffffff;"&gt;mxd.saveACopy(r'\\Gis Server Data\Replicas\test\Copy_of_test.mxd')&lt;/SPAN&gt;&lt;BR style="background-color: #ffffff;" /&gt;&lt;SPAN style="background-color: #ffffff;"&gt;del mxd&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 May 2018 22:00:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/using-arcpy-mapping-to-change-the-datasource-for/m-p/56642#M306</guid>
      <dc:creator>DarylHochhalter</dc:creator>
      <dc:date>2018-05-31T22:00:59Z</dc:date>
    </item>
  </channel>
</rss>

