<?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: Update cursors and feature datasets in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-cursors-and-feature-datasets/m-p/642248#M50070</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anytime something "sometimes" works, it is always more challenging to sort out.&amp;nbsp; When it doesn't work, what is the result?&amp;nbsp; Do you get error messages or unexpected results?&amp;nbsp; Sharing the specifics is helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking at the code, you use KEY_FIELD but you don't show it as being defined anywhere.&amp;nbsp; How is that variable setup?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Jun 2018 13:09:44 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2018-06-28T13:09:44Z</dc:date>
    <item>
      <title>Update cursors and feature datasets</title>
      <link>https://community.esri.com/t5/python-questions/update-cursors-and-feature-datasets/m-p/642247#M50069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Having a&amp;nbsp;problem using an update cursor to add values to a field in a feature class that is in a feature dataset and has topology.&amp;nbsp; This code always works outside of a feature dataset and sometimes works inside a feature dataset without topology.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; UPDATE_FIELD = [error_field] + KEY_FIELD&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor (features, UPDATE_FIELD) as cursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; key = tuple (row [1:])&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if key in error:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row [0] = error [key]&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow (row)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cursor&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&amp;nbsp; &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Jun 2018 07:22:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursors-and-feature-datasets/m-p/642247#M50069</guid>
      <dc:creator>DaleRichter</dc:creator>
      <dc:date>2018-06-28T07:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Update cursors and feature datasets</title>
      <link>https://community.esri.com/t5/python-questions/update-cursors-and-feature-datasets/m-p/642248#M50070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anytime something "sometimes" works, it is always more challenging to sort out.&amp;nbsp; When it doesn't work, what is the result?&amp;nbsp; Do you get error messages or unexpected results?&amp;nbsp; Sharing the specifics is helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking at the code, you use KEY_FIELD but you don't show it as being defined anywhere.&amp;nbsp; How is that variable setup?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Jun 2018 13:09:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursors-and-feature-datasets/m-p/642248#M50070</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-06-28T13:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Update cursors and feature datasets</title>
      <link>https://community.esri.com/t5/python-questions/update-cursors-and-feature-datasets/m-p/642249#M50071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The KEY_FIELD is defined, that was just an incomplete snippet of the code.&amp;nbsp; Here is some example code with error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt;&amp;gt;&amp;gt;&amp;gt; p = r'D:\_RE_MAKE_TEST\eiu.gdb\albers\pre'&amp;nbsp; # belongs to pre_Topology&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt;&amp;gt;&amp;gt;&amp;gt; UPDATE_FIELD = ["ERROR"]&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt;&amp;gt;&amp;gt;&amp;gt; features = p&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt;&amp;gt;&amp;gt;&amp;gt; &lt;/SPAN&gt;&lt;SPAN style="color: #004da8; font-family: 'Courier New'; font-size: 12pt;"&gt;with&lt;/SPAN&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt; arcpy.da.UpdateCursor (features, UPDATE_FIELD) &lt;/SPAN&gt;&lt;SPAN style="color: #004da8; font-family: 'Courier New'; font-size: 12pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt; cursor:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #004da8; font-family: 'Courier New'; font-size: 12pt;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt; row &lt;/SPAN&gt;&lt;SPAN style="color: #004da8; font-family: 'Courier New'; font-size: 12pt;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt; cursor:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x = row&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: #e60000; font-family: 'Courier New'; font-size: 12pt;"&gt;Runtime error &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: #e60000; font-family: 'Courier New'; font-size: 12pt;"&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: #e60000; font-family: 'Courier New'; font-size: 12pt;"&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 2, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt 5pt; text-indent: -5pt;"&gt;&lt;SPAN style="color: #e60000; font-family: 'Courier New'; font-size: 12pt;"&gt;RuntimeError: Objects in this class cannot be updated outside an edit session &lt;PRE&gt;&lt;/PRE&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin: 0cm 0cm 0pt;"&gt;&lt;SPAN style="color: black; font-family: 'Courier New'; font-size: 12pt;"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; font-family: Calibri; font-size: medium;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I think I have found a solution.&amp;nbsp; If I do the update cursor inside an edit session it works.&amp;nbsp; Which is a bit messy but it works.&amp;nbsp; Not having used this approach before does this code look alright?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def update_error_field_EDIT (features, UPDATE_FIELD, error):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; fds = os.path.dirname (features)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; assert "FeatureDataset" == arcpy.Describe(fds).dataType&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; gdb = os.path.dirname (fds)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; assert is_geodatabase (gdb)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit = arcpy.da.Editor (gdb)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.startEditing (False, False)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.startOperation ()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; update_error_field (features, UPDATE_FIELD, error)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.stopOperation ()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; edit.stopEditing (True)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; del edit&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Jun 2018 23:11:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursors-and-feature-datasets/m-p/642249#M50071</guid>
      <dc:creator>DaleRichter</dc:creator>
      <dc:date>2018-06-28T23:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: Update cursors and feature datasets</title>
      <link>https://community.esri.com/t5/python-questions/update-cursors-and-feature-datasets/m-p/642250#M50072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your feature class is in a feature dataset that has either a network or topology defined, then I believe you have to use an edit session, as the error indicates.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Jun 2018 19:33:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-cursors-and-feature-datasets/m-p/642250#M50072</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-06-29T19:33:54Z</dc:date>
    </item>
  </channel>
</rss>

