# Author: ESRI # Date: July 5, 2010 # Version: ArcGIS 10.0 # Purpose: This script generates a report of each page layout element and its # associated properties. This script is intended to run as a scrip tool # and requires two parameters: # 1) Input map document, # 2) Output text file. import arcpy, os, datetime #Read parameters from tool mxdPath = arcpy.GetParameterAsText(0) output = arcpy.GetParameterAsText(1) try: #Create r/w output file outFile = open(output, "w") #Generate Report header outFile.write("PageLayout Element Report: ") outFile.write(" ") outFile.write("This report lists the properties of invidual page layout elements within a single MXD. ") outFile.write(" ") outFile.write("MXD location: " + mxdPath + " ") outFile.write(" ") outFile.write("Date: " + str(datetime.datetime.today().strftime("%B %d, %Y")) + " ") outFile.write(" ") #Reference MXD file mxd = arcpy.mapping.MapDocument(mxdPath) #Report data frame elements if len(arcpy.mapping.ListLayoutElements(mxd, "DATAFRAME_ELEMENT")) > 0: outFile.write(" ") outFile.write(" DATA FRAME ELEMENTS: ") for elm in arcpy.mapping.ListLayoutElements(mxd, "DATAFRAME_ELEMENT"): outFile.write(" ") outFile.write(" Name: " + elm.name + " ") outFile.write(" X Position: " + str(elm.elementPositionX) + " ") outFile.write(" Y Position: " + str(elm.elementPositionY) + " ") outFile.write(" Height: " + str(elm.elementHeight) + " ") outFile.write(" Width: " + str(elm.elementWidth) + " ") #Report graphic elements if len(arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT")) > 0: outFile.write(" ") outFile.write(" GRAPHIC ELEMENTS: ") for elm in arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT"): outFile.write(" ") outFile.write(" Name: " + elm.name + " ") outFile.write(" X Position: " + str(elm.elementPositionX) + " ") outFile.write(" Y Position: " + str(elm.elementPositionY) + " ") outFile.write(" Height: " + str(elm.elementHeight) + " ") outFile.write(" Width: " + str(elm.elementWidth) + " ") #Report legend elements if len(arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")) > 0: outFile.write(" ") outFile.write(" LEGEND ELEMENTS: ") for elm in arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT"): outFile.write(" ") outFile.write(" Name: " + elm.name + " ") outFile.write(" Parent data frame: " + elm.parentDataFrameName + " ") outFile.write(" Title: " + elm.title + " ") outFile.write(" X Position: " + str(elm.elementPositionX) + " ") outFile.write(" Y Position: " + str(elm.elementPositionY) + " ") outFile.write(" Height: " + str(elm.elementHeight) + " ") outFile.write(" Width: " + str(elm.elementWidth) + " ") #Report map surround elements if len(arcpy.mapping.ListLayoutElements(mxd, "MAPSURROUND_ELEMENT")) > 0: outFile.write(" ") outFile.write(" MAP SURROUND ELEMENTS: ") for elm in arcpy.mapping.ListLayoutElements(mxd, "MAPSURROUND_ELEMENT"): outFile.write(" ") outFile.write(" Name: " + elm.name + " ") outFile.write(" Parent data frame: " + elm.parentDataFrameName + " ") outFile.write(" X Position: " + str(elm.elementPositionX) + " ") outFile.write(" Y Position: " + str(elm.elementPositionY) + " ") outFile.write(" Height: " + str(elm.elementHeight) + " ") outFile.write(" Width: " + str(elm.elementWidth) + " ") #Report picture elements if len(arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT")) > 0: outFile.write(" ") outFile.write(" PICTURE ELEMENTS: ") for elm in arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT"): outFile.write(" ") outFile.write(" Name: " + elm.name + " ") outFile.write(" X Position: " + str(elm.elementPositionX) + " ") outFile.write(" Y Position: " + str(elm.elementPositionY) + " ") outFile.write(" Height: " + str(elm.elementHeight) + " ") outFile.write(" Width: " + str(elm.elementWidth) + " ") #Report text elements if len(arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")) > 0: outFile.write(" ") outFile.write(" TEXT ELEMENTS: ") for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"): outFile.write(" ") outFile.write(" Name: " + elm.name + " ") outFile.write(" Text string: " + elm.text + " ") outFile.write(" X Position: " + str(elm.elementPositionX) + " ") outFile.write(" Y Position: " + str(elm.elementPositionY) + " ") outFile.write(" Height: " + str(elm.elementHeight) + " ") outFile.write(" Width: " + str(elm.elementWidth) + " ") #Close the file outFile.close() #Automatically open the file in associated TXT application os.startfile(output) #Delete all variables del mxdPath, outFile, mxd, output except Exception, e: import traceback map(arcpy.AddError, traceback.format_exc().split(" ")) arcpy.AddError(str(e))