AnsweredAssumed Answered

Changing of python code

Question asked by jibbh on Mar 22, 2015
Latest reply on Mar 25, 2015 by dkwiens

Hi

I found this Code by   Yanli Zhang, Stephen F. Austin State University  online

I am not familiair with python but this script is exactly what I need, except that I do not have years but attribute names like WRBDeAA01 or WNHDeAA51 (list of attribute names)

How do I have to change the loop so the code runs through these attributes instead of years?

Thanks

 

 

import arcpy, os

#Specify the map document and the data frame

mxd = arcpy.mapping.MapDocument(r"C:\temp\pine.mxd")

df = arcpy.mapping.ListDataFrames(mxd, "layers")[0]

outPath = r"C:\temp\output\\"    #output file folder

#Year (2004, 2003, ...) is used as attribute field name

#Also it is used to control the loop

year = 2004 



while year >= 1860:       # 1860 is the last year in the attribute table

    for maplayer in arcpy.mapping.ListLayers(mxd):

        if maplayer.name == "Pine":

            #chang the symbology

if maplayer.symbologyType == "GRADUATED_SYMBOLS":

                maplayer.symbology.valueField = str(year)

                maplayer.symbology.classBreakValues = [0, 20.0, 30.0, 40.0, \

50.0, 60.0, 70.0, 80.0, \

90.0, 100.0, 110.0, 120.0, \

130.0, 140.0, 150.0]

                maplayer.symbology.classBreakLabels = ["0 to 19.99", "20 to 29.99", "30 to 39.99", \

   "40 to 49.99", "50 to 59.99", "60 to 69.99", \

   "70 to 79.99", "80 to 89.99", "90 to 99.99", \

   "100 to 109.99", "110 to 119.99", \

   "120 to 129.99", "130 to 139.99", \

   "140 to 150"]

    # Change title for each map

    for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):

        if elm.text.find("Plot 4 Year")>= 0:

            elm.text = "Plot 4 Year " + str(year)

   

#export each map as a jpeg file. Also we can use ExportToPDF method.

nameJPEG = outPath + str(year) + ".jpg"   #spedify each output file name

arcpy.mapping.ExportToJPEG(mxd, nameJPEG)   

year = year - 1

del mxd, df

Outcomes