<?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: Calculate field with Code Block doesn't work in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-code-block-doesn-t-work/m-p/1231508#M62222</link>
    <description>&lt;P&gt;you put in two elif checks but you don't cover the case where 0's appear.&amp;nbsp;&lt;/P&gt;&lt;P&gt;More importantly, your def doesn't have any 'return' statements.&lt;/P&gt;&lt;P&gt;Your Arcade expression basically does an else if both are equal to 1, or the first doesn't equal 1. so to backtrack on your python code it would be&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def computeType(fid_c, fid_r):
    if (fid_c == 1) and (fid_r==1):
        return 'coupe et reboisement'
    elif fid_c == 1:
        return 'coupe'
    return 'reboisement'&lt;/LI-CODE&gt;&lt;P&gt;But I would check if you want fidc to return 'coupe' if it equals 0?&amp;nbsp; So play around with the possible combinations and what you actually want returned for all the cases of the two fieds ,,,, ie,&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;0&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;0&amp;nbsp; 0&lt;/P&gt;</description>
    <pubDate>Mon, 14 Nov 2022 22:30:14 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2022-11-14T22:30:14Z</dc:date>
    <item>
      <title>Calculate field with Code Block doesn't work</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-code-block-doesn-t-work/m-p/1231474#M62219</link>
      <description>&lt;P&gt;I am trying to calculate a field in a model builder, using &lt;EM&gt;if statements&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;In the 'Calculate Field' window, I create a new attribute 'perturbateur' (string)&lt;/P&gt;&lt;P&gt;the formula to calulate this attribute refers to a code Block below, which shows no error. But I only get null values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;perturbat=&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;computeType(!FID_Buffer_coupes_Dissolve!, !FID_Reboisement_Dissolve!)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code Block&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def computeType(fid_c, fid_r):
    if fid_c== 1 and fid_r==1:
        perturbat = 'coupe et reboisement'
    elif fid_c== 1:
        perturbat = 'coupe'
    elif fid_r==1:
        perturbat = 'reboisement'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you help me understanding what is wrong ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 21:47:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-code-block-doesn-t-work/m-p/1231474#M62219</guid>
      <dc:creator>JulietteLapeyre</dc:creator>
      <dc:date>2022-11-14T21:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field with Code Block doesn't work</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-code-block-doesn-t-work/m-p/1231497#M62220</link>
      <description>&lt;P&gt;It works with Arcade, but I am still interested in knowing how to do with Python3&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if ($feature.FID_Buffer_coupes_Dissolve==1 &amp;amp;&amp;amp; $feature.FID_Reboisement_Dissolve==1) {
    return 'coupe et reboisement'
}
else if ($feature.FID_Buffer_coupes_Dissolve==1) {
    return 'coupe'
}
else {
    return 'reboisement'
}&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 14 Nov 2022 22:14:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-code-block-doesn-t-work/m-p/1231497#M62220</guid>
      <dc:creator>JulietteLapeyre</dc:creator>
      <dc:date>2022-11-14T22:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field with Code Block doesn't work</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-code-block-doesn-t-work/m-p/1231508#M62222</link>
      <description>&lt;P&gt;you put in two elif checks but you don't cover the case where 0's appear.&amp;nbsp;&lt;/P&gt;&lt;P&gt;More importantly, your def doesn't have any 'return' statements.&lt;/P&gt;&lt;P&gt;Your Arcade expression basically does an else if both are equal to 1, or the first doesn't equal 1. so to backtrack on your python code it would be&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def computeType(fid_c, fid_r):
    if (fid_c == 1) and (fid_r==1):
        return 'coupe et reboisement'
    elif fid_c == 1:
        return 'coupe'
    return 'reboisement'&lt;/LI-CODE&gt;&lt;P&gt;But I would check if you want fidc to return 'coupe' if it equals 0?&amp;nbsp; So play around with the possible combinations and what you actually want returned for all the cases of the two fieds ,,,, ie,&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;0&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;0&amp;nbsp; 0&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 22:30:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-code-block-doesn-t-work/m-p/1231508#M62222</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-11-14T22:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field with Code Block doesn't work</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-code-block-doesn-t-work/m-p/1231753#M62254</link>
      <description>&lt;P&gt;It works great, thanks DanPatterson!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 15:14:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-with-code-block-doesn-t-work/m-p/1231753#M62254</guid>
      <dc:creator>JulietteLapeyre</dc:creator>
      <dc:date>2022-11-15T15:14:00Z</dc:date>
    </item>
  </channel>
</rss>

