CaspianKid

Indentation Help

Discussion created by CaspianKid on Apr 15, 2013
Latest reply on Apr 15, 2013 by CaspianKid
I have a simple script below which iterates through a FC and sets each ObjectID as a Definition Query.  When I run the script the only output is of the last feature.  I believe that my identation is messed up.  Any help would be appreciated.  Thanks.

# Import modules
import sys
import arcpy

# Set map document
mxd = arcpy.mapping.MapDocument("CURRENT")

#Calculate OID field
arcpy.CalculateField_management("Monitor", "OID_", '!OBJECTID!', "PYTHON")


for row in arcpy.SearchCursor("Monitor"):

    #Gets OID value for definition query
    rows = arcpy.SearchCursor("Monitor")
    for row in rows:
     DefQuery= row.getValue("OID_")

    #Set String Values for Definition Query
    strOID_DQ = "OID_ = '" + DefQuery + "'"
    
    # Define definition queries, extent, and scale for Plot layer in Layers data frame
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
    lyr = arcpy.mapping.ListLayers(mxd, "Monitor", df)[0]
    lyr.definitionQuery = strOID_DQ
    df.extent = lyr.getExtent()
    df.scale = df.scale * 1.25

    #Populate TitleBox text box
    TitleBox = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "TitleBox")[0]
    rows = arcpy.SearchCursor("Monitor")
    textValue = "" 
    for row in rows:
        textValue+= row.getValue("Landowner")+ " Tract"
    TitleBox.text = (textValue)

    # Define definition query, extent, and scale for Plot layer in Overview data frame
    df = arcpy.mapping.ListDataFrames(mxd, "Overview")[0]
    lyr = arcpy.mapping.ListLayers(mxd, "Monitor", df)[0]
    lyr.definitionQuery = strOID_DQ
    df.extent = lyr.getExtent()
    df.scale = 100000

    # Refresh map to show all changes
    arcpy.RefreshActiveView()

    # Save map document and export to PDF
    strPath = r"C:\Projects\ForestStewardship\FY2013_Monitoring\\"
    mxd.saveACopy(strPath + textValue + ".mxd")
    arcpy.mapping.ExportToPDF(mxd, strPath + textValue + ".pdf")

del mxd

Outcomes