<?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 Stopiteration error and failure with CalculateField_Management update cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/stopiteration-error-and-failure-with/m-p/1060993#M61222</link>
    <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to run a field calculation on a set of selected features from my layer. While my custom button may be considered "functioning" when I hard program into the python window on arcmap, I'll get an error on my update cursor saying" stopiteration: iteration not started". Additionally, when I do manage to get my print statement back, the calculation isn't being run, I'm getting statements such as "This is the new acreage: layer name" for however many polygons I've selected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it can be done using calculate geometry, but I'd like to be able to streamline this process as it'll be used when subdivisions are drawn out and save on the amount of button clicks for each individual polygon. I have to calculate the geometry for both fields "calc_acre" (acres) and "shape_leng" (sq ft), but I'm currently trying to get calc_acre working before I move to the next row.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import pythonaddins

class CalcGeometry(object):
    """Implementation for CalcGeometry_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
		mxd = arcpy.mapping.MapDocument('current')
		Fields = ["CALC_ACRE", "SHAPE_LENG"]
        lyr = arcpy.mapping.ListLayers(mxd)[0]
        sample = lyr.getSelectionSet()
		with arcpy.da.UpdateCursor(lyr, Fields) as Calc:
			for row in Calc: 
				row[0] = arcpy.CalculateField_management(lyr, "CALC_ACRE", "!shape.area@acres!", "PYTHON", "" )
				print("this is the new acreage: {}".format(row[0]))	
			Calc.updateRow(row)&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 24 May 2021 15:33:17 GMT</pubDate>
    <dc:creator>kad37_pns</dc:creator>
    <dc:date>2021-05-24T15:33:17Z</dc:date>
    <item>
      <title>Stopiteration error and failure with CalculateField_Management update cursor</title>
      <link>https://community.esri.com/t5/python-questions/stopiteration-error-and-failure-with/m-p/1060993#M61222</link>
      <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to run a field calculation on a set of selected features from my layer. While my custom button may be considered "functioning" when I hard program into the python window on arcmap, I'll get an error on my update cursor saying" stopiteration: iteration not started". Additionally, when I do manage to get my print statement back, the calculation isn't being run, I'm getting statements such as "This is the new acreage: layer name" for however many polygons I've selected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know it can be done using calculate geometry, but I'd like to be able to streamline this process as it'll be used when subdivisions are drawn out and save on the amount of button clicks for each individual polygon. I have to calculate the geometry for both fields "calc_acre" (acres) and "shape_leng" (sq ft), but I'm currently trying to get calc_acre working before I move to the next row.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import pythonaddins

class CalcGeometry(object):
    """Implementation for CalcGeometry_addin.button (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
		mxd = arcpy.mapping.MapDocument('current')
		Fields = ["CALC_ACRE", "SHAPE_LENG"]
        lyr = arcpy.mapping.ListLayers(mxd)[0]
        sample = lyr.getSelectionSet()
		with arcpy.da.UpdateCursor(lyr, Fields) as Calc:
			for row in Calc: 
				row[0] = arcpy.CalculateField_management(lyr, "CALC_ACRE", "!shape.area@acres!", "PYTHON", "" )
				print("this is the new acreage: {}".format(row[0]))	
			Calc.updateRow(row)&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 24 May 2021 15:33:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopiteration-error-and-failure-with/m-p/1060993#M61222</guid>
      <dc:creator>kad37_pns</dc:creator>
      <dc:date>2021-05-24T15:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Stopiteration error and failure with CalculateField_Management update cursor</title>
      <link>https://community.esri.com/t5/python-questions/stopiteration-error-and-failure-with/m-p/1061031#M61224</link>
      <description>&lt;P&gt;CalculateField_management is not designed to be used in a cursor.&amp;nbsp; It does the calculations on a featureclass all at once.&amp;nbsp; If you want to use a cursor, then get the geometry and use arcpy methods to calculate the area.&lt;/P&gt;</description>
      <pubDate>Mon, 24 May 2021 16:53:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopiteration-error-and-failure-with/m-p/1061031#M61224</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-05-24T16:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: Stopiteration error and failure with CalculateField_Management update cursor</title>
      <link>https://community.esri.com/t5/python-questions/stopiteration-error-and-failure-with/m-p/1061083#M61225</link>
      <description>&lt;P&gt;I would also like to add that you probably want to be using "PYTHON_9.3" as the&amp;nbsp;&lt;SPAN&gt;expression_type parameter for CalculateField.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 May 2021 19:09:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/stopiteration-error-and-failure-with/m-p/1061083#M61225</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-05-24T19:09:35Z</dc:date>
    </item>
  </channel>
</rss>

