<?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: Mapping Replace Workspaces issue in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141367#M10985</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think your previous code was not doing anything because the for loop was iterating through every letter (element) in the fileFolder string.&amp;nbsp; Since they were single characters, no value was returned for the [-4:] slice, thus nothing happened.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Aug 2012 02:53:21 GMT</pubDate>
    <dc:creator>BruceBacia</dc:creator>
    <dc:date>2012-08-13T02:53:21Z</dc:date>
    <item>
      <title>Mapping Replace Workspaces issue</title>
      <link>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141363#M10981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have the following code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy
fileFolder = r"G:\ProjectF\GIS\Projects\INRMP\Burlington\GIS_Maps"
oldSpace = r"G:\ProjectF\GIS\Projects\INRMP\Burlington\GIS_Data\Burlington GIS\ANG_Burlington\ANG_Burlington_CIP.mdb\cadastre\installation_area"
newSpace = r"G:\ProjectF\GIS\Projects\INRMP\Burlington\GIS_Data\Burlington GIS\VTANG_Boundary.shp"

for element in fileFolder:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fileType = element[-4:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; if fileType == ".mxd":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(element)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.replaceWorkspaces(oldSpace,"ACCESS_WORKSPACE",newSpace,"SHAPEFILE_WORKSPACE")
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The premise is simple.&amp;nbsp; Iterate through a number of mxd files in the fileFolder location and change the source for one of the layers.&amp;nbsp; There are other files, so to prevent the silly "Invalid MXD filename" error, I added an if clause which checks for the fileType variable.&amp;nbsp; This variable is set to the last four characters of the file, so it would know if the file is an mxd.&amp;nbsp; If the fileType is an mxd, it replaces the old .mdb source with the new .shp source.&amp;nbsp; The problem is this: the script runs with no errors, but does not actually replace the source file in the corresponding mxds.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Ben S.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Aug 2012 13:59:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141363#M10981</guid>
      <dc:creator>BenSloboda</dc:creator>
      <dc:date>2012-08-09T13:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: Mapping Replace Workspaces issue</title>
      <link>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141364#M10982</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ben,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;try &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
mxd.save()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;as the last line in your inner loop.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Thomas&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:47:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141364#M10982</guid>
      <dc:creator>ThomasEmge</dc:creator>
      <dc:date>2021-12-11T07:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Mapping Replace Workspaces issue</title>
      <link>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141365#M10983</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you used print statements to verify that your logic for identifying mxd files is passing the correct values to arcpy.mapping.MapDocument()?.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 00:40:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141365#M10983</guid>
      <dc:creator>BruceBacia</dc:creator>
      <dc:date>2012-08-13T00:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Mapping Replace Workspaces issue</title>
      <link>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141366#M10984</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You could try built in python methods to get mxds&amp;nbsp; instead of your own logic&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy, os
fileFolder = r"G:\ProjectF\GIS\Projects\INRMP\Burlington\GIS_Maps\\"
dirs = os.listdir(fileFolder)
maps = [(fileFolder + dir) for dir in dirs if dir.endswith(".mxd")]
oldSpace = r"G:\ProjectF\GIS\Projects\INRMP\Burlington\GIS_Data\Burlington GIS\ANG_Burlington\ANG_Burlington_CIP.mdb\cadastre\installation_area"
newSpace = r"G:\ProjectF\GIS\Projects\INRMP\Burlington\GIS_Data\Burlington GIS\VTANG_Boundary.shp"

for map in maps:
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument(map)
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.replaceWorkspaces(oldSpace,"ACCESS_WORKSPACE",newSpace,"SHAPEFILE_WORKSPACE")
&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.save()
&amp;nbsp;&amp;nbsp;&amp;nbsp; del mxd
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:47:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141366#M10984</guid>
      <dc:creator>BruceBacia</dc:creator>
      <dc:date>2021-12-11T07:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Mapping Replace Workspaces issue</title>
      <link>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141367#M10985</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think your previous code was not doing anything because the for loop was iterating through every letter (element) in the fileFolder string.&amp;nbsp; Since they were single characters, no value was returned for the [-4:] slice, thus nothing happened.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Aug 2012 02:53:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141367#M10985</guid>
      <dc:creator>BruceBacia</dc:creator>
      <dc:date>2012-08-13T02:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Mapping Replace Workspaces issue</title>
      <link>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141368#M10986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Btw, it looks like the replace Workspace method will replace the workspaces for all layers in the mxd.&amp;nbsp; If you only want to replace the source for one layer you will need to use layer.replaceDataSource.&amp;nbsp; Pseudocode below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
For each map doc in fileFolder:
&amp;nbsp;&amp;nbsp;&amp;nbsp; For each layer in map doc:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if layer.dataSource = oldSpace:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.replaceDataSource with newSpace
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;If you need any help writing this let me know.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:47:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/mapping-replace-workspaces-issue/m-p/141368#M10986</guid>
      <dc:creator>BruceBacia</dc:creator>
      <dc:date>2021-12-11T07:47:42Z</dc:date>
    </item>
  </channel>
</rss>

