AnsweredAssumed Answered

If else statement not working in Python

Question asked by mmolter on Feb 5, 2013
Latest reply on Feb 19, 2013 by mmolter

I have a Python script to generate an automated mapbook. I want to be able to adjust the data frame scale based on the size of the parcel. My if/else statement is not working. I think it's because it's not recognizing the acreage field in the Parcels table and/or it says it cannot combine a string with an integer. Here is my sample where I create the map document, select the parcel based on user parameters, and zoom to selected feature. The parcels layer is stored in an SDE database.

# Process: Create Mapbook Document, Data Frame, and Layer Objects
mxd = mapping.MapDocument(r"V:\gislu\_BasemapMXD\10.1 MXDS\PreApp_Location.mxd")
df = mapping.ListDataFrames(mxd, "PreApp Location")[0]
Layer = mapping.ListLayers(mxd, "Parcels", df)[0]

#Process: Select Layer by Attributes
whereClause = "\"ADDRNO\" = " + NUMBER + " AND \"ADDRSTREET\" = '" + STREET + "'"
arcpy.AddMessage("SELECTING: " + whereClause)
arcpy.SelectLayerByAttribute_management (Layer, "NEW_SELECTION", whereClause)

#Process: Update the mapbook display in ArcMap
for Layer in mapping.ListLayers(mxd, "Parcels", df):
if [acreage] < str(153):
df.scale = 5000
df.scale = 9000
legend = mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")[0]
legend.autoAdd = True