<?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: Trouble using updateConnectionProperties in ArcPy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163804#M64336</link>
    <description>&lt;P&gt;We've had mixed success with &lt;EM&gt;findAndReplaceWorkspacePath&lt;/EM&gt; for mxds.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os
arcpy.env.overwriteOutput = True

# get mxd
mxd_pth = r"W:\GISRequests\DCI\2016MJ\2016_MJ_project.mxd"
mxd = arcpy.mapping.MapDocument(mxd_pth)
oldpth = r"W:\GISRequests\DCI\2016MJ"
newpth = r"W:\GISRequests\DCI\2016MJp\2016 MJ Project Geodatabase.gdb"

featureclasses = arcpy.mapping.ListLayers(mxd)

for lyr in featureclasses:
    lyrname = lyr.name
    if lyr.supports("DATASOURCE"):
        if lyr.dataSource == os.path.join(oldpth, lyrname):
            arcpy.AddMessage("Updating: {}".format(lyrname))
            lyr.findAndReplaceWorkspacePath(oldpth, newpth)
mxd.save()
del mxd&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Apr 2022 10:10:22 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2022-04-13T10:10:22Z</dc:date>
    <item>
      <title>Trouble using updateConnectionProperties in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163373#M64329</link>
      <description>&lt;P&gt;I have inherited a number of ArcMap projects, where the data sources have been broken by various people's file admin. Shapefiles have been moved from one folder to another, but subdirectory organisation remains the same. I am trying to fix the links using&amp;nbsp;updateConnectionProperties. I use the following code on individual shapefiles, but cannot get the desired result.&lt;/P&gt;&lt;P&gt;variable "newsource" returns a correct filepath (printed by line 7) but I think line 8 is the problem as "not possible" is printed. No errors are returned. Any help appreciated. Thanks&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Users\CAddison\Documents\ArcGIS\Test001.mxd")
for lyr in arcpy.mapping.ListLayers(mxd):
	try:
		oldsource = lyr.dataSource
		newsource = oldsource[0:53]+str("\\NEW\\")+oldsource[65:]
		print newsource
		lyr.updateConnectionProperties(oldsource, newsource)
	except:
		print "not possible"&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 08:18:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163373#M64329</guid>
      <dc:creator>Cjaddison82</dc:creator>
      <dc:date>2022-04-12T08:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble using updateConnectionProperties in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163376#M64330</link>
      <description>&lt;P&gt;python 3 versus python 2.&amp;nbsp; Try&lt;/P&gt;&lt;P&gt;print(newsource)&lt;/P&gt;&lt;P&gt;print("Not Possible")&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 08:45:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163376#M64330</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-04-12T08:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble using updateConnectionProperties in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163412#M64333</link>
      <description>&lt;P&gt;Could it be that updateConnectionProperties method is only for Pro aprx projects, not ArcMaP mxd?&lt;/P&gt;&lt;P&gt;&lt;A href="https://desktop.arcgis.com/de/arcmap/latest/analyze/arcpy-mapping/updatingandfixingdatasources.htm" target="_blank"&gt;Updating and fixing data sources with arcpy.mapping—ArcMap | Dokumentation (arcgis.com)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 10:58:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163412#M64333</guid>
      <dc:creator>JohannesBierer</dc:creator>
      <dc:date>2022-04-12T10:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble using updateConnectionProperties in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163416#M64334</link>
      <description>&lt;P&gt;Thanks Dan. Will try later, but since running the script resulted in newsource being printed and "not possible" also being printed, I'm not sure if this will fix the data links. Will try though, and thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2022 11:47:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163416#M64334</guid>
      <dc:creator>Cjaddison82</dc:creator>
      <dc:date>2022-04-12T11:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble using updateConnectionProperties in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163804#M64336</link>
      <description>&lt;P&gt;We've had mixed success with &lt;EM&gt;findAndReplaceWorkspacePath&lt;/EM&gt; for mxds.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy, os
arcpy.env.overwriteOutput = True

# get mxd
mxd_pth = r"W:\GISRequests\DCI\2016MJ\2016_MJ_project.mxd"
mxd = arcpy.mapping.MapDocument(mxd_pth)
oldpth = r"W:\GISRequests\DCI\2016MJ"
newpth = r"W:\GISRequests\DCI\2016MJp\2016 MJ Project Geodatabase.gdb"

featureclasses = arcpy.mapping.ListLayers(mxd)

for lyr in featureclasses:
    lyrname = lyr.name
    if lyr.supports("DATASOURCE"):
        if lyr.dataSource == os.path.join(oldpth, lyrname):
            arcpy.AddMessage("Updating: {}".format(lyrname))
            lyr.findAndReplaceWorkspacePath(oldpth, newpth)
mxd.save()
del mxd&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 10:10:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163804#M64336</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-04-13T10:10:22Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble using updateConnectionProperties in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163810#M64337</link>
      <description>&lt;P&gt;Thanks a lot. This looks really useful, will give it a whirl. Pardon my ignorance, but does your "newpth" have to direct to a .gdb? Can this be used for individual .shp as I'm trying to do, where the .shp hasn't been added to a .gdb?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 10:29:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163810#M64337</guid>
      <dc:creator>Cjaddison82</dc:creator>
      <dc:date>2022-04-13T10:29:09Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble using updateConnectionProperties in ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163811#M64338</link>
      <description>&lt;P&gt;No, it can be a folder if needed.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Apr 2022 10:32:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-using-updateconnectionproperties-in-arcpy/m-p/1163811#M64338</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-04-13T10:32:39Z</dc:date>
    </item>
  </channel>
</rss>

