<?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: Problems to save mxd with removed broken Links in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471567#M36801</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Felix:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had a similar problem when I performed an SDE conversion from 9.1 to 9.3 using VBA.&amp;nbsp; In this case, we created another SDE database on a new server with ArcGIS v9.3.&amp;nbsp; After running this conversion, some layers were still looking for the 9.1 connections which caused the mxd to hang when opening because the 9.1 database and server was now retired.&amp;nbsp; I was unable to locate the old connections, so I added a dummy domain name to route the connections with the old server name to the new server name.&amp;nbsp; This solved the problem, but the mxd still contains references to the old server.&amp;nbsp; The only way to fix this is to recreate the entire mxd (time consuming and we have hundreds of files like this).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It seems that the newly saved mxd might still have references to the old server which causes it to hang.&amp;nbsp; I guess saving it again outside of python removes these references as you are then able to open the mxd in a normal amount of time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have any 3rd party software that is used in this mxd?&amp;nbsp; This could be a cause of your problems.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, I would contact tech support and log an incident with them to see if the SaveACopy is supposed to flush out references to old servers.&amp;nbsp; I would be interested in the results as I will need to perform this operation on thousands of mxds when my organization migrates from Oracle Client 10g to either 11 or 12 depending upon when my organization is ready for this upgrade.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 27 Feb 2012 15:38:00 GMT</pubDate>
    <dc:creator>MichaelVolz</dc:creator>
    <dc:date>2012-02-27T15:38:00Z</dc:date>
    <item>
      <title>Problems to save mxd with removed broken Links</title>
      <link>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471566#M36800</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've written a Pyhton script which lists all layers, layer with broken links &amp;amp; datasources of a Project. At the end all datasources &amp;amp; layers with broken links are removed and a copy of the mxd is saved.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The trouble start if I have broken links to our former geoserver. When I run my script it removes those datasources properly. But to open the newly saved project takes ages, eventhough the datasource &amp;amp; layer is removed! So after 5 minutes it opens (if there was only one removed datasource). Now I can save it (ctrl+s) and then it opens with normal speed (&amp;lt;30 second).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have any solutions or tips for this problem?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;felix&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def startAnalysis(inputMxd, destLogFile):
 lyrName, lyrSavedName, brokenLayerName=r"Dataframe: Grouplayer\Layer; Datasource","\n\nSaved layer: ","\n\nBroken Links:"
 mxd = arcpy.mapping.MapDocument(inputMxd)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for df in arcpy.mapping.ListDataFrames(mxd):&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # nacheinander alle Dataframes in Projekt verwenden
&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd, "", df):&amp;nbsp;&amp;nbsp; # nacheinander alle Layer in Dataframe verwenden
&amp;nbsp;&amp;nbsp; lyrName=lyrName + "\n" + df.name + ";" + lyr.longName
&amp;nbsp;&amp;nbsp; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrName=lyrName + ";" + lyr.dataSource&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # speichern des "Dataframes;(Grouplayer)/Layer"
&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 blnSaveLayer.get():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.saveACopy(lyr.name)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrSavedName=lyrSavedName + "\n" + lyr.name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; pass

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; brokenList=arcpy.mapping.ListBrokenDataSources (df)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for brokenLyr in brokenList:
&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; arcpy.mapping.RemoveLayer(df, brokenLyr)
&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; try:
&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; brokenLayerName=brokenLayerName + "\n" + df.name + brokenLyr.longName + "; " + brokenLyr.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; except:
&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; print "Error: " +brokenLyr

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ouputMsg= lyrName + lyrSavedName + lyrNotSavedName + brokenLayerName
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f = open(destLogFile, "w")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.write(ouputMsg.encode("utf8"))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f.close()

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd.saveACopy(os.path.splitext(inputMxd)[0]+"_WithoutBrokenLinks.mxd")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Feb 2012 13:27:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471566#M36800</guid>
      <dc:creator>FelixSvoboda</dc:creator>
      <dc:date>2012-02-27T13:27:29Z</dc:date>
    </item>
    <item>
      <title>Re: Problems to save mxd with removed broken Links</title>
      <link>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471567#M36801</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Felix:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had a similar problem when I performed an SDE conversion from 9.1 to 9.3 using VBA.&amp;nbsp; In this case, we created another SDE database on a new server with ArcGIS v9.3.&amp;nbsp; After running this conversion, some layers were still looking for the 9.1 connections which caused the mxd to hang when opening because the 9.1 database and server was now retired.&amp;nbsp; I was unable to locate the old connections, so I added a dummy domain name to route the connections with the old server name to the new server name.&amp;nbsp; This solved the problem, but the mxd still contains references to the old server.&amp;nbsp; The only way to fix this is to recreate the entire mxd (time consuming and we have hundreds of files like this).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It seems that the newly saved mxd might still have references to the old server which causes it to hang.&amp;nbsp; I guess saving it again outside of python removes these references as you are then able to open the mxd in a normal amount of time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have any 3rd party software that is used in this mxd?&amp;nbsp; This could be a cause of your problems.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, I would contact tech support and log an incident with them to see if the SaveACopy is supposed to flush out references to old servers.&amp;nbsp; I would be interested in the results as I will need to perform this operation on thousands of mxds when my organization migrates from Oracle Client 10g to either 11 or 12 depending upon when my organization is ready for this upgrade.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 Feb 2012 15:38:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471567#M36801</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2012-02-27T15:38:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problems to save mxd with removed broken Links</title>
      <link>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471568#M36802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for your imput.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'll do some further test (replace the layers datasource and then save the file) and contact the tech support about the SaveACopy issue. I'll update about the progress.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;felix&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2012 11:28:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471568#M36802</guid>
      <dc:creator>FelixSvoboda</dc:creator>
      <dc:date>2012-02-28T11:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Problems to save mxd with removed broken Links</title>
      <link>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471569#M36803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There are a couple of statements I'd question.&amp;nbsp; I'd like to see if you have the same issue with the following, simplified code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
path = "XXX"
mxd = arcpy.mapping.MapDocument(path)
for df in arcpy.mapping.ListDataFrames(mxd):
&amp;nbsp; for lyr in arcpy.mapping.ListBrokenDataSources(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.mapping.RemoveLayer(df, lyr)

newPath = "YYY"
mxd.saveACopy(newPath)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also - what SP are you on?&amp;nbsp; We did make some changes to saveACopy in a past MXD.&amp;nbsp; I'll research this a little more.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:52:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471569#M36803</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-11T20:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problems to save mxd with removed broken Links</title>
      <link>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471570#M36804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for your input Jeff.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I should have posted the more simplified code. But it doesn't solve the problem. I'll post a mxd where I removed one layer with broken data connection. It takes a while to open the empty mxd. If you save the project it opens with normal speed. I think Michael is right and the mxd still has references to the old server.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried it with SP 2 (Build 3200) &amp;amp; 3 (Build 3600).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;felix&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Feb 2012 06:39:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471570#M36804</guid>
      <dc:creator>FelixSvoboda</dc:creator>
      <dc:date>2012-02-29T06:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: Problems to save mxd with removed broken Links</title>
      <link>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471571#M36805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Felix:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As a workaround you might want to write a script that just saves the file through python before running the BrokenLinks script.&amp;nbsp; Maybe the Save operation flushes out old SDE connections, but the SaveACopy operation does not.&amp;nbsp; Are the mxds that you are processing currently saved as v9.3 or earlier?&amp;nbsp; Or have these mxds been created or saved previously in v10?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I had some issues where I tried to run python scripts on v9.3 mxds where they crashed python in v10 and I was unable to open the mxd in v10.&amp;nbsp; If I save the file in v9.3 or I saved the mxd back to v9.3 in python, the mxd would then open in v10.&amp;nbsp; It seems that this Save operation in v9.3 was flushing out bad or corrupt objects for v10.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Feb 2012 13:03:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471571#M36805</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2012-02-29T13:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Problems to save mxd with removed broken Links</title>
      <link>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471572#M36806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm having the same problem in version 10.3.1. Did you ever figure out how to fix this problem?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2016 18:41:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471572#M36806</guid>
      <dc:creator>PhilipGriffith</dc:creator>
      <dc:date>2016-05-27T18:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problems to save mxd with removed broken Links</title>
      <link>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471573#M36807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Never mind: found the solution on &lt;A _jive_internal="true" href="https://community.esri.com/thread/170372"&gt;this post&lt;/A&gt;. You can get the code &lt;A href="https://github.com/Esri/developer-support/blob/master/arcsde-sql/python/refresh-mxd-layers/refresh-mxd-layers.py"&gt;here&lt;/A&gt;. Or just work the logic into your script; it's not difficult.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 May 2016 18:50:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-to-save-mxd-with-removed-broken-links/m-p/471573#M36807</guid>
      <dc:creator>PhilipGriffith</dc:creator>
      <dc:date>2016-05-27T18:50:10Z</dc:date>
    </item>
  </channel>
</rss>

