<?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: python script to calculate field values used to work - now it doesn't. in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606445#M20139</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Seems that you're mixing Python syntax with VB syntax in the CalculateField expression.&amp;nbsp; VB uses the square bracket notation for field names, as in [my_field] and in Python the notation is exclamation point, as in !my_field!&amp;nbsp; I noticed that you're using Python in your modelbuilder version but VB in your script.&amp;nbsp; Try using Python and the exclamation point throughout and see what happens.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've actually tried VB and Python (and every punctuation mark I could think of) and neither works. I ran out of things to try and ended up just doing this in ArcMap. I think the Calculate_Field tool is buggy or something because it works sometimes and othertimes it doesn't.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 Jun 2010 20:53:12 GMT</pubDate>
    <dc:creator>JoshuaChan</dc:creator>
    <dc:date>2010-06-02T20:53:12Z</dc:date>
    <item>
      <title>python script to calculate field values used to work - now it doesn't.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606441#M20135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a python script that adds a hectares field and then calculates its&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;value using the Area field. This worked fine last week but for some&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;reason it gives null values this week.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;code :&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# final resultant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.Identity_analysis (interimFC, "THLB_Lyr", finalFC )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Getting the name of the area field for our resultant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;descObj = gp.Describe(finalFC)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;areaField = descObj.AreaFieldName&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print areaField, 'is the fieldname for Area'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# ADD a HECTARES COLUMN = 'AREA_HA'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.AddField_management(finalFC, "AREA_HA", "DOUBLE", "", "", "", "",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"NULLABLE", "NON_REQUIRED", "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# CALCULATE AREA_HA using AREA FIELD&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print 'calculating Hectares field'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;hectaresCalc = '"' + '[' + areaField + ']/10000' + '"'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;print hectaresCalc&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management(finalFC, "AREA_HA", hectaresCalc, "VB",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;"")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I got that syntax from the ArcToolbox. I don't know why it suddenly&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;stopped working. I swear this worked last week. Now I get a resultant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dataset that has AREA_HA added but it's values are all null.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestions or ideas?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 18:03:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606441#M20135</guid>
      <dc:creator>JoshuaChan</dc:creator>
      <dc:date>2010-05-27T18:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: python script to calculate field values used to work - now it doesn't.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606442#M20136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried doing this in model builder and it still doesn't work. Now the error message is :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Executing (Calculate Field): CalculateField W:\srm\sry\Workarea\jhchan\wksp\testing_ground.gdb\DCK_FD AREA_HA [GEOMETRY_Area]/10000 PYTHON # W:\srm\sry\Workarea\jhchan\wksp\testing_ground.gdb\DCK_FD&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Start Time: Thu May 27 16:35:23 2010&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000539: Error running expression: [GEOMETRY_Area]/10000 &amp;lt;type 'exceptions.NameError'&amp;gt;: name 'GEOMETRY_Area' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;A locator with this name does not exist.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Calculate Field).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End Time: Thu May 27 16:35:23 2010 (Elapsed Time: 0.00 seconds)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But if I look at the feature class the item name "GEOMETRY_Area" does in fact exist. So why does Python and Model builder think it does not exist?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 May 2010 22:36:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606442#M20136</guid>
      <dc:creator>JoshuaChan</dc:creator>
      <dc:date>2010-05-27T22:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: python script to calculate field values used to work - now it doesn't.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606443#M20137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I encountered something slightly similar where I was doing a search cursor to search for values that I wanted to calculate field in a seperate new clipped dataset.&amp;nbsp; I solved the issue by using an update cursor on the target instead of using calculate field.&amp;nbsp; (When I was using calculate field sometimes it would work and sometimes not and it would never hit my print statements!!) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Use an update cursor.&amp;nbsp; Good luck.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 30 May 2010 11:06:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606443#M20137</guid>
      <dc:creator>justinperez</dc:creator>
      <dc:date>2010-05-30T11:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: python script to calculate field values used to work - now it doesn't.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606444#M20138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Seems that you're mixing Python syntax with VB syntax in the CalculateField expression.&amp;nbsp; VB uses the square bracket notation for field names, as in [my_field] and in Python the notation is exclamation point, as in !my_field!&amp;nbsp; I noticed that you're using Python in your modelbuilder version but VB in your script.&amp;nbsp; Try using Python and the exclamation point throughout and see what happens.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 May 2010 18:51:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606444#M20138</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2010-05-31T18:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: python script to calculate field values used to work - now it doesn't.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606445#M20139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Seems that you're mixing Python syntax with VB syntax in the CalculateField expression.&amp;nbsp; VB uses the square bracket notation for field names, as in [my_field] and in Python the notation is exclamation point, as in !my_field!&amp;nbsp; I noticed that you're using Python in your modelbuilder version but VB in your script.&amp;nbsp; Try using Python and the exclamation point throughout and see what happens.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've actually tried VB and Python (and every punctuation mark I could think of) and neither works. I ran out of things to try and ended up just doing this in ArcMap. I think the Calculate_Field tool is buggy or something because it works sometimes and othertimes it doesn't.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Jun 2010 20:53:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606445#M20139</guid>
      <dc:creator>JoshuaChan</dc:creator>
      <dc:date>2010-06-02T20:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: python script to calculate field values used to work - now it doesn't.</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606446#M20140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I've actually tried VB and Python (and every punctuation mark I could think of) and neither works. I ran out of things to try and ended up just doing this in ArcMap. I think the Calculate_Field tool is buggy or something because it works sometimes and othertimes it doesn't.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It is more likely that you have data that causes a crash in the expression. If you use the field calculator you do not have the opportunity to trap data errors in a try/except block and its impossible to see what record caused it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Since the CalculateField simply wraps the expression in a cursor, it is much much better to use your own cursor in a script and do the expression inside a try/except block. CalculateField is more useful in interactive processes or models.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jun 2010 13:22:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-script-to-calculate-field-values-used-to/m-p/606446#M20140</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2010-06-03T13:22:11Z</dc:date>
    </item>
  </channel>
</rss>

