ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

ListBrokenDataSources

  • Summary
  • Discussion
  • Syntax
  • Code Sample

Summary

Returns a Python list of Layer objects within a map document (.mxd) or layer (.lyr) file that have broken connections to their original source data.

Discussion

ListBrokenDataSources always returns a Python list object even if only one broken layer is returned. In order to return a single layer object, an index value must be used on the list (e.g., brkLyr = arcpy.mapping.ListBrokenDataSources(mxd)[0]). For loops on a list provide an easy mechanism to iterate through each item in the list (e.g., for brkLyr in arcpy.mapping.ListBrokenDataSources(mxd):).

Some layers within a map document or layer file may be password protected because the user and password information is not saved within the layer file or map document. Map documents that contain these layers typically prompt the user to enter the appropriate information while the document is opening. The arcpy.mapping scripting environment will, by default, supress these dialogs during execution but that means that the layers will be treated as though they have broken data sources. In otherwords, secured layers will not be rendered in any output. If it is necessary for these layers to render appropriately then there are a couple of options. First, save the username and password information with the layers. Second, the CreateArcSDEConnectionFile geoprocessing function allows you to create a connection that is persisted in memory. If this command is used prior to opening a map document (.mxd) with the MapDocument function or a layer file with the Layer function, then SDE layers will render and not appear as broken. Currently, there is not an alternative for secured web services. See the Layer help for a code example.

To learn more about automating the repair of broken layers, refer to: Updating and Fixing Data Sources.

Syntax

ListBrokenDataSources (map_document_or_layer)
ParameterExplanationData Type
map_document_or_layer

A variable that references a MapDocument or Layer object.

Object

Return Value

Data TypeExplanation
Layer

A Python list of Layer objects.

Code Sample

ListBrokenDataSources example:

This script will search for broken data sources in all map documents that exist in a single folder. A report with map document names and broken sources will be printed.

import arcpy, os
path = r"C:\Project"
for fileName in os.listdir(path):
    fullPath = os.path.join(path, fileName)
    if os.path.isfile(fullPath):
        basename, extension = os.path.splitext(fullPath)
        if extension == ".mxd":
            mxd = arcpy.mapping.MapDocument(fullPath)
            print "MXD: " + fileName
            brknList = arcpy.mapping.ListBrokenDataSources(mxd)
            for brknItem in brknList:
                print "\t" + brknItem.name
del mxd
Feedback on this topic?

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal