<?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 Calculate Field in Python in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-in-python/m-p/1083151#M43785</link>
    <description>&lt;P&gt;Hello!&lt;BR /&gt;I'm dabbling back into python and scripting (it's been about 7 years since I last wrote scripts) and I'm trying to create a script tool to help with some of my property data updates that I do as part of my workload, I typically do all of this manually, so this tool will greatly&amp;nbsp;&lt;SPAN&gt;cut down the time it takes to do this task&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm getting hung up on the Calculate Field function and I'm hoping you all can help me:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My shapefile has three fields ('USER_FNAME', 'USER_LNAME' and 'USER_CORPN') that I'm pulling information from to populate a new field: '&lt;STRONG&gt;NAME&lt;/STRONG&gt;'.&amp;nbsp; I want the script to first-off populate &lt;STRONG&gt;NAME&lt;/STRONG&gt; with&amp;nbsp;!USER_LNAME! + " " + !USER_FNAME! &lt;EM&gt;(easy, done...)&lt;/EM&gt; but then, I would like to then select all values that are blank (or " ") in the &lt;STRONG&gt;NAME&lt;/STRONG&gt; field and calculate the selected records to populate &lt;STRONG&gt;NAME&lt;/STRONG&gt; with !USER_CORPN!. This way, it doesn't overwrite the !USER_LNAME! + " " + !USER_FNAME! statement.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I feel like I possibly need an if/else statement or something in the code block but I'm getting lost in all the arc help documents lol.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Jul 2021 17:33:26 GMT</pubDate>
    <dc:creator>KirstenDuncan</dc:creator>
    <dc:date>2021-07-27T17:33:26Z</dc:date>
    <item>
      <title>Calculate Field in Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-in-python/m-p/1083151#M43785</link>
      <description>&lt;P&gt;Hello!&lt;BR /&gt;I'm dabbling back into python and scripting (it's been about 7 years since I last wrote scripts) and I'm trying to create a script tool to help with some of my property data updates that I do as part of my workload, I typically do all of this manually, so this tool will greatly&amp;nbsp;&lt;SPAN&gt;cut down the time it takes to do this task&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I'm getting hung up on the Calculate Field function and I'm hoping you all can help me:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My shapefile has three fields ('USER_FNAME', 'USER_LNAME' and 'USER_CORPN') that I'm pulling information from to populate a new field: '&lt;STRONG&gt;NAME&lt;/STRONG&gt;'.&amp;nbsp; I want the script to first-off populate &lt;STRONG&gt;NAME&lt;/STRONG&gt; with&amp;nbsp;!USER_LNAME! + " " + !USER_FNAME! &lt;EM&gt;(easy, done...)&lt;/EM&gt; but then, I would like to then select all values that are blank (or " ") in the &lt;STRONG&gt;NAME&lt;/STRONG&gt; field and calculate the selected records to populate &lt;STRONG&gt;NAME&lt;/STRONG&gt; with !USER_CORPN!. This way, it doesn't overwrite the !USER_LNAME! + " " + !USER_FNAME! statement.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I feel like I possibly need an if/else statement or something in the code block but I'm getting lost in all the arc help documents lol.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 17:33:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-in-python/m-p/1083151#M43785</guid>
      <dc:creator>KirstenDuncan</dc:creator>
      <dc:date>2021-07-27T17:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field in Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-in-python/m-p/1083257#M43803</link>
      <description>&lt;P&gt;Something like the following should do it all in one step. It is only checking that the first name and last name have empty strings, not that they are null, so you may need to modify the if statement to match your data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;expression = "getName(!USER_FNAME!,!USER_LNAME!,!USER_CORPN!)"

codeblock = """
def getName(fname, lname, corpn):
    if fname=="" and lname=="":
        return corpn
    else:
        return fname + " " + lname
"""

arcpy.CalculateField_management(&amp;lt;table&amp;gt;, "NAME", expression, "PYTHON3",  codeblock)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another way to do this would be with an update cursor.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jul 2021 20:05:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-in-python/m-p/1083257#M43803</guid>
      <dc:creator>Tim_McGinnes</dc:creator>
      <dc:date>2021-07-27T20:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field in Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-in-python/m-p/1083446#M43837</link>
      <description>&lt;P&gt;This is excellent and exactly what I needed!! Thank you so so much!! &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jul 2021 11:47:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-in-python/m-p/1083446#M43837</guid>
      <dc:creator>KirstenDuncan</dc:creator>
      <dc:date>2021-07-28T11:47:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field in Python</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-in-python/m-p/1277151#M67811</link>
      <description>&lt;P&gt;In my opinion, field calculation IF statements are unnecessarily cumbersome. I proposed a new kind of mechanism here:&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-ideas/virtual-attributes-ad-hoc/idi-p/127647" target="_blank" rel="noopener"&gt;Idea - Virtual Attributes (ad hoc)&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 02:27:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/calculate-field-in-python/m-p/1277151#M67811</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2023-04-11T02:27:45Z</dc:date>
    </item>
  </channel>
</rss>

