<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: If else statement not working in Python in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601723#M47020</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you everyone! The idea about using if/elif statement for the data frame scale worked and was the easiest route to go! I hadn't thought about it that way so thanks for the good idea.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 19 Feb 2013 14:04:48 GMT</pubDate>
    <dc:creator>MollyWatson</dc:creator>
    <dc:date>2013-02-19T14:04:48Z</dc:date>
    <item>
      <title>If else statement not working in Python</title>
      <link>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601719#M47016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Create Mapbook Document, Data Frame, and Layer Objects&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = mapping.MapDocument(r"V:\gislu\_BasemapMXD\10.1 MXDS\PreApp_Location.mxd")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df = mapping.ListDataFrames(mxd, "PreApp Location")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Layer = mapping.ListLayers(mxd, "Parcels", df)[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Process: Select Layer by Attributes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;whereClause = "\"ADDRNO\" = " + NUMBER + " AND \"ADDRSTREET\" = '" + STREET + "'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage("SELECTING: " + whereClause)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management (Layer, "NEW_SELECTION", whereClause)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage(arcpy.GetCount_management(Layer).getOutput(0))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#Process: Update the mapbook display in ArcMap&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;df.zoomToSelectedFeatures()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for Layer in mapping.ListLayers(mxd, "Parcels", df):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if [acreage] &amp;lt; str(153):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; df.scale = 5000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; df.scale = 9000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RefreshActiveView()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.RefreshTOC()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;legend = mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;legend.autoAdd = True&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 17:56:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601719#M47016</guid>
      <dc:creator>MollyWatson</dc:creator>
      <dc:date>2013-02-05T17:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: If else statement not working in Python</title>
      <link>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601720#M47017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There seem to be a number of issues here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, I don't think you can get to a feature attribute by querying a layer object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Nor can presenting a field name to the layer get you anywhere: layer objects don't have fields&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;They do have names and sources and max scales and whatnot.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;you need to access the (lone) feature you expect to find in that layer to test the field's value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As well, are the values in [acreage] really strings? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You present it with a string (str(153), which is really "153")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but expect it to resolve a less-than test...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;This likely causes your "string with an integer" error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;int([acreage]) &amp;lt; "153" is more likely to work, if [acreage] really is a string....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(edit -&amp;gt; oops, that is right, int([acreage]) &amp;lt; 153 is what I meant.... )&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 18:47:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601720#M47017</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2013-02-05T18:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: If else statement not working in Python</title>
      <link>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601721#M47018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Also, please enclose your code in code tags.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd try&lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt; int([acreage]) &amp;lt; 153&lt;/PRE&gt;&lt;SPAN&gt;, without the quotes around 153.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 20:16:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601721#M47018</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2013-02-05T20:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: If else statement not working in Python</title>
      <link>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601722#M47019</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;nbsp;&amp;nbsp; &lt;PRE class="plain" name="code"&gt;# 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]&amp;nbsp; #Process: Select Layer by Attributes whereClause = "\"ADDRNO\" = " + NUMBER + " AND \"ADDRSTREET\" = '" + STREET + "'" arcpy.AddMessage("SELECTING: " + whereClause) arcpy.SelectLayerByAttribute_management (Layer, "NEW_SELECTION", whereClause) arcpy.AddMessage(arcpy.GetCount_management(Layer).getOutput(0)) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #Process: Update the mapbook display in ArcMap df.zoomToSelectedFeatures() for Layer in mapping.ListLayers(mxd, "Parcels", df): &amp;nbsp;&amp;nbsp;&amp;nbsp; if [acreage] &amp;lt; str(153): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.scale = 5000 &amp;nbsp;&amp;nbsp;&amp;nbsp; else: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.scale = 9000 arcpy.RefreshActiveView() arcpy.RefreshTOC() legend = mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")[0] legend.autoAdd = True&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please note the [post=166129]use of the [noparse]&lt;/SPAN&gt;&lt;PRE class="plain" name="code"&gt;&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;SPAN&gt;[/noparse] block[/post] to format your code in the forum.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mark is correct that you can't get the value this way. Do you want the total acreage of the selected features? You could determine that using the Summary Statistics tool. If you only have one parcel selected, you could get the acreage value out of the table using a search cursor on your layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What if your parcel is long and skinny? Seems to me a safer approach would be to examine the &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;df.scale&lt;/SPAN&gt;&lt;SPAN&gt; after you zoom to selected and decide based on that which standard scale to use:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;if df.scale &amp;lt;= 5000: &amp;nbsp; df.scale = 5000 elif df.scale &amp;lt;= 9000: &amp;nbsp; df.scale = 9000&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 20:20:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601722#M47019</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-02-05T20:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: If else statement not working in Python</title>
      <link>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601723#M47020</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you everyone! The idea about using if/elif statement for the data frame scale worked and was the easiest route to go! I hadn't thought about it that way so thanks for the good idea.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Feb 2013 14:04:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/if-else-statement-not-working-in-python/m-p/601723#M47020</guid>
      <dc:creator>MollyWatson</dc:creator>
      <dc:date>2013-02-19T14:04:48Z</dc:date>
    </item>
  </channel>
</rss>

