<?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: arcpy.mapping replaceDataSource error message in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1415376#M70463</link>
    <description>&lt;P&gt;Good morning Tom,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply, I do not know if this will work as the name of the new data is not the same as the previous - the findAndReplaceWorkspacePath looks for data of the same name in a new path (from my understanding).&lt;BR /&gt;&lt;BR /&gt;Also in line 6 - what are you setting the 2 "Data" variables to ?&lt;BR /&gt;&lt;BR /&gt;Thanks again&lt;/P&gt;</description>
    <pubDate>Thu, 25 Apr 2024 15:45:01 GMT</pubDate>
    <dc:creator>BrodieChisholm</dc:creator>
    <dc:date>2024-04-25T15:45:01Z</dc:date>
    <item>
      <title>arcpy.mapping replaceDataSource error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414858#M70451</link>
      <description>&lt;P&gt;Good day all,&lt;BR /&gt;&lt;BR /&gt;I am trying to automate a process at my work, the script will start by updating the data source for a layer file (.lyr) found at the top of the contents pane in a map document.&lt;BR /&gt;&lt;BR /&gt;The original data source for the layer file is a shapefile and I am trying to update it to a new shapefile found in a workspace/ folder I have assigned the variable "path" to (see screenshot below).&lt;/P&gt;&lt;P&gt;The following screenshot is, from my understanding, a simple way to write the code. I was using the python window in ArcMap for troubleshooting purposes:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrodieChisholm_0-1713976717114.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/102033i7791267EDB5BAF29/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BrodieChisholm_0-1713976717114.png" alt="BrodieChisholm_0-1713976717114.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As you can see I receive an error message.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried writing this script several different ways, even omitting the map document and pointing straight to the layer file (arcpy.mapping.Layer([path])) but continue to get this error message.&lt;BR /&gt;&lt;BR /&gt;The mapdocument is added ("mxd"), as is the dataframe ("df"), and the layer ("lyr").&lt;/P&gt;&lt;P&gt;Upon reading through past post regarding the .replaceDataSource function, I have seen I am not the first to receive this error message.&lt;/P&gt;&lt;P&gt;I am just starting to write my own scripts and apologize if I reffered to anything incorrectly.&lt;BR /&gt;&lt;BR /&gt;Has anyone figured out how to get past/ correct the error?&lt;/P&gt;&lt;P&gt;Any help with this is greatly appreciated.&lt;/P&gt;&lt;P&gt;Here is the script as I have it written in an IDE, it's not complete but useful for context:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os

#Define variables
mxd = arcpy.mapping.MapDocument(r"D:\Brodie\Projects\2024\2024 IMT Templates\yyyymmdd_XXX###_OPS_TABLOID_LAND.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
lyr = arcpy.mapping.ListLayers(mxd, "", df)[0]
path = r"D:\Brodie\Projects\2023\AFFESIncidentData2023\SUD017_2023\IncidentData\\" #Path to new source data
nom = "20230613_1900_SUD017_MAP.shp" #Name of new source data

#Update data source for fire perimeter .lyr
lyr.replaceDataSource(path, "SHAPEFILE_WORKSPACE", nom)
lyr.name = "20230613_1900_SUD017_MAP" #Name of updated layer as it appears in the contents pane

#Save mxd under new name
mxd.saveACopy(r"D:\Brodie\Projects\2023\AFFESIncidentData2023\SUD017_2023\Projects\20230613_1900_SUD017_OPS_TABLOID_LAND.mxd")
print "Script complete"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 18:41:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414858#M70451</guid>
      <dc:creator>BrodieChisholm</dc:creator>
      <dc:date>2024-04-24T18:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping replaceDataSource error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414902#M70455</link>
      <description>&lt;P&gt;I haven't done this in ArcMap, but your path doesn't look right. Try removing the two trailing back slashes.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 18:13:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414902#M70455</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-04-24T18:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping replaceDataSource error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414924#M70456</link>
      <description>&lt;P&gt;Good afternoon,&lt;BR /&gt;Thank you for your response - I tried removing the two back slashes but am receiving the same error.&lt;BR /&gt;&lt;BR /&gt;I added the script as it is written in an IDE to the original post.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 18:39:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414924#M70456</guid>
      <dc:creator>BrodieChisholm</dc:creator>
      <dc:date>2024-04-24T18:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping replaceDataSource error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414939#M70457</link>
      <description>&lt;P&gt;Maybe use None for the wildcard parameter instead of an empty string.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df = arcpy.mapping.ListDataFrames(mxd, None)[0]
lyr = arcpy.mapping.ListLayers(mxd, None, df)[0]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 19:20:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414939#M70457</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-04-24T19:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping replaceDataSource error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414956#M70458</link>
      <description>&lt;P&gt;Good afternoon,&lt;BR /&gt;&lt;BR /&gt;Again, I appreciate your insights and thoughts on a solution.&lt;BR /&gt;&lt;BR /&gt;Unfortunately, I tried using None for the wildcard parameter and received the same error message.&lt;BR /&gt;&lt;BR /&gt;I would do this in Pro but the organisation I work for is still using ArcMap for certain processes - so trying to get this to work in ArcMap/ Python 2.7.&lt;BR /&gt;&lt;BR /&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 19:43:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414956#M70458</guid>
      <dc:creator>BrodieChisholm</dc:creator>
      <dc:date>2024-04-24T19:43:28Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping replaceDataSource error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414959#M70459</link>
      <description>&lt;P&gt;I've used variations of this script:&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/updatingandfixingdatasources.htm" target="_blank" rel="noopener"&gt;Updating and fixing data sources with arcpy.mapping&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.supports("DATASOURCE"):
        if lyr.dataSource == r"C:\Project\Data\Parcels.gdb\MapIndex":
            lyr.findAndReplaceWorkspacePath(r"Data", r"Data2")
mxd.saveACopy(r"C:\Project\Project2.mxd")
del mxd&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 19:54:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1414959#M70459</guid>
      <dc:creator>Tom_Laue</dc:creator>
      <dc:date>2024-04-24T19:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping replaceDataSource error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1415376#M70463</link>
      <description>&lt;P&gt;Good morning Tom,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply, I do not know if this will work as the name of the new data is not the same as the previous - the findAndReplaceWorkspacePath looks for data of the same name in a new path (from my understanding).&lt;BR /&gt;&lt;BR /&gt;Also in line 6 - what are you setting the 2 "Data" variables to ?&lt;BR /&gt;&lt;BR /&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 15:45:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1415376#M70463</guid>
      <dc:creator>BrodieChisholm</dc:creator>
      <dc:date>2024-04-25T15:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.mapping replaceDataSource error message</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1647281#M74673</link>
      <description>&lt;P&gt;Hello, I am Jin-tae Kim&lt;BR /&gt;I reviewed the information you shared and thought it might be helpful, so I’m leaving a reply.&lt;/P&gt;&lt;P&gt;Since some time has passed, you may have already resolved the issue in another way. If so, it would be great if you could share your solution as well.&lt;/P&gt;&lt;P&gt;As far as I have seen, when working with a shapefile, the data source specified in the arcpy.layer.replaceDataSource function should not include the file extension.&lt;BR /&gt;I recommend removing the extension and trying again.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2025 08:14:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-mapping-replacedatasource-error-message/m-p/1647281#M74673</guid>
      <dc:creator>jinte0107</dc:creator>
      <dc:date>2025-09-02T08:14:01Z</dc:date>
    </item>
  </channel>
</rss>

