Guest User

Untitled

a guest
Jul 31st, 2012
219
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Author:  ESRI
  2. # Date:    July 5, 2010
  3. # Version: ArcGIS 10.0
  4. # Purpose: This script will iterate through each MXD in a folder and report information about each
  5. #          map document, it's data frames and layers.  The script is intended to run from a script
  6. #          tool that requires two input parameters:
  7. #               1) folder containing MXDs,
  8. #               2) an output text file.
  9. #
  10. #          The resulting text file will automatically open.
  11.  
  12. import arcpy, datetime, os
  13.  
  14. try:
  15.  
  16.     arcpy.gp.overwriteOutput = True
  17.  
  18.     #Read input parameters from GP dialog
  19.     folderPath = arcpy.GetParameterAsText(0)
  20.     output = arcpy.GetParameterAsText(1)
  21.  
  22.     #Create an output file
  23.     outFile = open(output, "w")
  24.  
  25.     #Report header
  26.     outFile.write("MXD REPORT: \n")
  27.     outFile.write("\n")
  28.     outFile.write("This report is for all MXDs in a folder.  It lists relevant information about\n")
  29.     outFile.write("map document properties, data frame, layer, and table information for each MXD\n")
  30.     outFile.write("in a system folder\n")
  31.     outFile.write("\n")
  32.     outFile.write("Date: " + str(datetime.datetime.today().strftime("%B %d, %Y")) + "\n")
  33.  
  34.     #Loop through each MXD file
  35.     count = 0
  36.     for filename in os.listdir(folderPath):
  37.         fullpath = os.path.join(folderPath, filename)
  38.         if os.path.isfile(fullpath):
  39.             if filename.lower().endswith(".mxd"):
  40.  
  41.                 #Reference MXD
  42.                 mxd = arcpy.mapping.MapDocument(fullpath)
  43.                 count = 1
  44.  
  45.                 #Format output value
  46.                 if mxd.author =="": authorValue = "None"
  47.                 else: authorValue = mxd.author
  48.                 if mxd.summary =="": summaryValue = "None"
  49.                 else: summaryValue = mxd.summary
  50.                 BDS = arcpy.mapping.ListBrokenDataSources(mxd)
  51.                 if len(BDS) == 0: BDSValue = "None"
  52.                 else: BDSValue = "A total of " + str(len(BDS)) + " broken data source(s)."
  53.                
  54.                 #Write MXD data to file
  55.                 outFile.write("\n")
  56.                 outFile.write("\n")
  57.                 outFile.write("------------------------------------------------------------------- \n")
  58.                 outFile.write("MAPDOCUMENT: " + os.path.basename(mxd.filePath) + "\n")
  59.                 outFile.write("------------------------------------------------------------------- \n")
  60.                 outFile.write("\n")
  61.                 outFile.write("\t Path:                 " + mxd.filePath + "\n")
  62.                 outFile.write("\t Last Saved:           " + str(mxd.dateSaved) + "\n")
  63.                 outFile.write("\t Author:               " + authorValue + "\n")
  64.                 outFile.write("\t Summary:              " + summaryValue + "\n")
  65.                 outFile.write("\t Relative Paths:       " + str(mxd.relativePaths) + "\n")
  66.                 outFile.write("\t Broken Data Sources:  " + BDSValue + "\n")
  67.  
  68.                 #Reference each data frame and report data
  69.                 DFList = arcpy.mapping.ListDataFrames(mxd)
  70.                 for df in DFList:
  71.                     #Format output values
  72.                     if df.description == "": descValue = "None"
  73.                     else: descValue = df.description
  74.  
  75.                     #Write data frame data to file
  76.                     outFile.write("\n")
  77.                     outFile.write("\n")
  78.                     outFile.write("\t DATA FRAME: " + df.name + "\n")
  79.                     outFile.write("\n")
  80.                     outFile.write("\t\t Description:        " + descValue + "\n")
  81.                     outFile.write("\t\t Spatial Reference:  " + df.spatialReference.name + "\n")
  82.                     outFile.write("\t\t Transformation(s):  " + str(df.geographicTransformations) + "\n")
  83.                     outFile.write("\t\t Map Units:          " + df.mapUnits + "\n")
  84.                     try:
  85.                         outFile.write("\t\t Scale:              " + str(df.scale) + "\n")
  86.                     except:
  87.                         outFile.write("\t\t Scale:              Unknown \n")
  88.                     outFile.write("\t\t Rotation:           " + str(df.rotation) + "\n")
  89.                  
  90.                     #Reference each layer in a data frame
  91.                     lyrList = arcpy.mapping.ListLayers(mxd, "", df)
  92.                     for lyr in lyrList:
  93.                         outFile.write("\n")
  94.                         outFile.write("\t\t LAYER: " + lyr.name + "\n")
  95.                         outFile.write("\t\t\t Group Layer Path:  " + lyr.longName + "\n")
  96.                         if lyr.supports("dataSource"):
  97.                             outFile.write("\t\t\t Data Source:       " + lyr.dataSource + "\n")
  98.                             try:
  99.                                 outFile.write("\t\t\t Dataset type:      " + arcpy.Describe(lyr.dataSource).datasettype + "\n")
  100.                             except:
  101.                                 outFile.write("\t\t\t Dataset type:     Unknown (could be a broken data source) \n")
  102.                         else: outFile.write("\t\t\t Data Source:       N/A \n")
  103.                         if lyr.supports("definitionQuery"):
  104.                             if lyr.definitionQuery == "":
  105.                                 outFile.write("\t\t\t Query Definition:  None \n" )
  106.                             else: outFile.write("\t\t\t Query Definition:  " + lyr.definitionQuery + "\n")
  107.                         else: outFile.write("\t\t\t Query Definition:  N/A \n")
  108.                        
  109.                     #Reference each table in a data frame
  110.                     tableList = arcpy.mapping.ListTableViews(mxd, df, "")
  111.                     for table in tableList:
  112.                         outFile.write("\n")
  113.                         outFile.write("\n")
  114.                         outFile.write("\t\t TABLEVIEW: " + table.name + "\n")
  115.                         outFile.write("\n")
  116.                         outFile.write("\t\t\t Data Source:           " + table.dataSource + "\n")
  117.                         if table.definitionQuery == "":
  118.                             outFile.write("\t\t\t Query Definition:      None \n")
  119.                         else: outFile.write("\t\t\t Query Definition:      " + table.definitionQuery + "\n")
  120.  
  121.                 del mxd
  122.            
  123.     if count ==0:
  124.         outFile.write("\n")
  125.         outFile.write("\n")
  126.         outFile.write("---------------------------------------------------------------------------------- \n")
  127.         outFile.write("                            NO MXD FILES FOUND \n")
  128.         outFile.write("---------------------------------------------------------------------------------- \n")                          
  129.  
  130.     outFile.close()
  131.  
  132.     #Open resulting text file
  133.     os.startfile(output)
  134.  
  135.     #Delete variables that reference data on disk
  136.     del folderPath, output, outFile, fullpath
  137.  
  138. except Exception, e:
  139.   import traceback
  140.   map(arcpy.AddError, traceback.format_exc().split("\n"))
  141.   arcpy.AddError(str(e))
RAW Paste Data