<?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: Code Block in Python Toolbox in ArcMap Questions</title>
    <link>https://community.esri.com/t5/arcmap-questions/code-block-in-python-toolbox/m-p/1094748#M2942</link>
    <description>&lt;P&gt;The following code is from one of the examples on the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_blank" rel="noopener"&gt;Calculate Field&lt;/A&gt; tool help page. Does that help?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;expression = "getClass(float(!SHAPE.area!))"
codeblock = """
def getClass(area):
    if area &amp;lt;= 1000:
        return 1
    if area &amp;gt; 1000 and area &amp;lt;= 10000:
        return 2
    else:
        return 3"""
 
# Execute CalculateField 
arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON3", codeblock)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Sep 2021 23:39:58 GMT</pubDate>
    <dc:creator>Tim_McGinnes</dc:creator>
    <dc:date>2021-09-01T23:39:58Z</dc:date>
    <item>
      <title>Code Block in Python Toolbox</title>
      <link>https://community.esri.com/t5/arcmap-questions/code-block-in-python-toolbox/m-p/1094550#M2941</link>
      <description>&lt;P&gt;How do you properly format a code block on a CalculateField in a python toollbox?&lt;/P&gt;&lt;P&gt;I receive an error similar to this:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "&amp;lt;string&amp;gt;", line 128, in execute&lt;BR /&gt;File "c:\program files (x86)\arcgis\desktop10.8\arcpy\arcpy\management.py", line 3647, in CalculateField&lt;BR /&gt;raise e&lt;BR /&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000989: Python syntax error: Parsing error IndentationError: unexpected indent (line 2)&lt;BR /&gt;Failed to execute (CalculateField).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 17:49:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/code-block-in-python-toolbox/m-p/1094550#M2941</guid>
      <dc:creator>MichaelStranovsky</dc:creator>
      <dc:date>2021-09-01T17:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Code Block in Python Toolbox</title>
      <link>https://community.esri.com/t5/arcmap-questions/code-block-in-python-toolbox/m-p/1094748#M2942</link>
      <description>&lt;P&gt;The following code is from one of the examples on the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/calculate-field.htm" target="_blank" rel="noopener"&gt;Calculate Field&lt;/A&gt; tool help page. Does that help?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;expression = "getClass(float(!SHAPE.area!))"
codeblock = """
def getClass(area):
    if area &amp;lt;= 1000:
        return 1
    if area &amp;gt; 1000 and area &amp;lt;= 10000:
        return 2
    else:
        return 3"""
 
# Execute CalculateField 
arcpy.CalculateField_management(inTable, fieldName, expression, "PYTHON3", codeblock)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 23:39:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcmap-questions/code-block-in-python-toolbox/m-p/1094748#M2942</guid>
      <dc:creator>Tim_McGinnes</dc:creator>
      <dc:date>2021-09-01T23:39:58Z</dc:date>
    </item>
  </channel>
</rss>

