flix

Problems to save mxd with removed broken Links

Discussion created by flix on Feb 27, 2012
Latest reply on May 27, 2016 by p_griffith
Hi
I've written a Pyhton script which lists all layers, layer with broken links & datasources of a Project. At the end all datasources & layers with broken links are removed and a copy of the mxd is saved.
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 & 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 (<30 second).

Do you have any solutions or tips for this problem?

thanks
felix

def startAnalysis(inputMxd, destLogFile):
 lyrName, lyrSavedName, brokenLayerName=r"Dataframe: Grouplayer\Layer; Datasource","\n\nSaved layer: ","\n\nBroken Links:"
 mxd = arcpy.mapping.MapDocument(inputMxd)
    for df in arcpy.mapping.ListDataFrames(mxd):            # nacheinander alle Dataframes in Projekt verwenden
  for lyr in arcpy.mapping.ListLayers(mxd, "", df):   # nacheinander alle Layer in Dataframe verwenden
   lyrName=lyrName + "\n" + df.name + ";" + lyr.longName
   try:
    lyrName=lyrName + ";" + lyr.dataSource      # speichern des "Dataframes;(Grouplayer)/Layer"
                if blnSaveLayer.get():
     lyr.saveACopy(lyr.name)
     lyrSavedName=lyrSavedName + "\n" + lyr.name
            except:
    pass

            brokenList=arcpy.mapping.ListBrokenDataSources (df)
            for brokenLyr in brokenList:
                arcpy.mapping.RemoveLayer(df, brokenLyr)
                try:
                    brokenLayerName=brokenLayerName + "\n" + df.name + brokenLyr.longName + "; " + brokenLyr.dataSource
                except:
                    print "Error: " +brokenLyr

        ouputMsg= lyrName + lyrSavedName + lyrNotSavedName + brokenLayerName
        f = open(destLogFile, "w")
        f.write(ouputMsg.encode("utf8"))
        f.close()

        mxd.saveACopy(os.path.splitext(inputMxd)[0]+"_WithoutBrokenLinks.mxd")

Outcomes