<?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: help with python in feild calculator in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184361#M64792</link>
    <description>&lt;P&gt;that worked well!&lt;/P&gt;&lt;P&gt;thank you so much!&lt;/P&gt;&lt;P&gt;but it still interesting why the python code didnt work...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Jun 2022 16:08:32 GMT</pubDate>
    <dc:creator>matu89</dc:creator>
    <dc:date>2022-06-20T16:08:32Z</dc:date>
    <item>
      <title>help with python in feild calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184140#M64783</link>
      <description>&lt;P&gt;hello , i have 8 points with Z value .&lt;/P&gt;&lt;P&gt;each 2 points is a pair ( see the colors in the image attached).&lt;/P&gt;&lt;P&gt;i created a new feild calles "Delta" that in their i want the result of the difference between a pair..&lt;/P&gt;&lt;P&gt;for example the difference between point 2 to 1 is 4.66 meters..&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="matu89_0-1655561542109.jpeg" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43786iC4A6E835C6682BDB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="matu89_0-1655561542109.jpeg" alt="matu89_0-1655561542109.jpeg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt; is there a way to do this via while or for loop ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for the help!&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jun 2022 14:12:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184140#M64783</guid>
      <dc:creator>matu89</dc:creator>
      <dc:date>2022-06-18T14:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: help with python in feild calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184143#M64784</link>
      <description>&lt;P&gt;I would use a &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/searchcursor-class.htm" target="_self"&gt;SearchCursor&amp;nbsp;&lt;/A&gt;to read all of the Z&amp;nbsp; values into a python dict - indexed by the objectid. Then loop through the feature class with an &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/updatecursor-class.htm" target="_self"&gt;UpdateCursor&lt;/A&gt; calculating the Delta value for each row and writing the result&lt;/P&gt;</description>
      <pubDate>Sat, 18 Jun 2022 15:45:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184143#M64784</guid>
      <dc:creator>DonMorrison1</dc:creator>
      <dc:date>2022-06-18T15:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: help with python in feild calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184165#M64785</link>
      <description>&lt;P&gt;Hey, i dont have a clue how to start writing the code...&lt;/P&gt;&lt;P&gt;can you please help me with that ?&lt;/P&gt;&lt;P&gt;thanks..!&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jun 2022 04:28:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184165#M64785</guid>
      <dc:creator>matu89</dc:creator>
      <dc:date>2022-06-19T04:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: help with python in feild calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184234#M64786</link>
      <description>&lt;P&gt;Open the Python window:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1655703668866.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43811iB79535379EDB0EED/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1655703668866.png" alt="JohannesLindner_0-1655703668866.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Copy the script below, paste it into the Python window, edit the first line, run it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fc_path_or_layer_name = "PointsWithZValues"
fields = ["OBJECTID", "Z", "Delta"]

z_dict = {r[0]: r[1] for r in arcpy.da.SearchCursor(fc_path_or_layer_name, fields)}
with arcpy.da.UpdateCursor(fc_path_or_layer_name, fields) as cursor:
    for oid, z, delta in cursor:
        # if OBJECTID is even, the partner oid is oid - 1
        # if OBJECTID is odd, the partner id is oid + 1
        partner_oid = oid + (-1 if oid % 2 == 0 else 1)
        delta = abs(z - z_dict[partner_oid])
        cursor.updateRow([oid, z, delta])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here, I used DoubleField as Z and TextField as Delta:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1655703793068.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43812iA3A60F1F62CC609D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_1-1655703793068.png" alt="JohannesLindner_1-1655703793068.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;!!! The script assumes that your screenshot shows exactly what your table looks like, especially that the pairs are always odd and even ObjectID. If this isn't the case, the script gets a little more complicated (but not much) !!!&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 05:46:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184234#M64786</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-20T05:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: help with python in feild calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184242#M64787</link>
      <description>&lt;P&gt;hey ,&lt;/P&gt;&lt;P&gt;thanks for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i tried to run the script, but it wont run..&lt;/P&gt;&lt;P&gt;here is the messege :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="matu89_0-1655707158327.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43814i09E966F5DD8B91F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="matu89_0-1655707158327.png" alt="matu89_0-1655707158327.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;what went wrong?&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 06:39:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184242#M64787</guid>
      <dc:creator>matu89</dc:creator>
      <dc:date>2022-06-20T06:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: help with python in feild calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184249#M64788</link>
      <description>&lt;P&gt;It couldn't find OBJECTID 2.&lt;/P&gt;&lt;P&gt;Clear all selections and try again. If it still doesn't work, you need the slightly more complicated script.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 07:57:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184249#M64788</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-20T07:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: help with python in feild calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184282#M64789</link>
      <description>&lt;P&gt;this time i get the following mmessege :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="matu89_0-1655727179617.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43823iEA00491476CE62B8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="matu89_0-1655727179617.png" alt="matu89_0-1655727179617.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 12:13:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184282#M64789</guid>
      <dc:creator>matu89</dc:creator>
      <dc:date>2022-06-20T12:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: help with python in feild calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184297#M64790</link>
      <description>&lt;P&gt;I hate that error so much... And it could have any number of reasons.&lt;/P&gt;&lt;P&gt;Try a different approach:&lt;/P&gt;&lt;P&gt;Calculate the field, switch language to Arcade, use the script below. Be sure to clear selections!&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var partner_oid = $feature.OBJECTID
if($feature.OBJECTID % 2 == 0) {
    partner_oid -= 1
} else {
    partner_oid += 1
}
var partner = First(Filter($featureset, "OBJECTID = @partner_oid"))
if(partner == null) { return null }
return Abs(partner.Z - $feature.Z)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1655730878193.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/43829i151AAAA18F71354D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1655730878193.png" alt="JohannesLindner_0-1655730878193.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 13:15:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184297#M64790</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-20T13:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: help with python in feild calculator</title>
      <link>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184361#M64792</link>
      <description>&lt;P&gt;that worked well!&lt;/P&gt;&lt;P&gt;thank you so much!&lt;/P&gt;&lt;P&gt;but it still interesting why the python code didnt work...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2022 16:08:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-with-python-in-feild-calculator/m-p/1184361#M64792</guid>
      <dc:creator>matu89</dc:creator>
      <dc:date>2022-06-20T16:08:32Z</dc:date>
    </item>
  </channel>
</rss>

