<?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: Problem in Field Calculator in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/problem-in-field-calculator/m-p/240786#M8205</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you have to supply it with a field name as a substitute for 'a'&lt;/P&gt;&lt;P&gt;the function should go in the code block section then the call to the is made in the expression box like&lt;/P&gt;&lt;P&gt;lblcal([yourfield]) if using VB or&amp;nbsp; lblcal(!yourfield!) if using the Python parser&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Jul 2015 10:41:44 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2015-07-13T10:41:44Z</dc:date>
    <item>
      <title>Problem in Field Calculator</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/problem-in-field-calculator/m-p/240785#M8204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Sir!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I tried to customize a field value in polygon featureclass. For that I wrote a python function. Then using Field Calculator, I copy this function to Pre_Logic Script Code: and call the function. it gives me error.&lt;/P&gt;&lt;P&gt;&amp;nbsp; Then I tried the same using Calculate Field tool in ArcToolbox. It works correctly.&lt;/P&gt;&lt;P&gt;Pl explain why I cannot run the above function using Field Calculator.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My function is given below:&lt;/P&gt;&lt;P&gt;def lblcal(a):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dic1 = {'11':'PP', '13':'TOPOPP', '14':'FTP', '15':'VP', '16':'FVP', '17':'CP', '18':'FCP', '19':'FSP', '20':'FSPP', '21':'ISPP', '22':'FUP'}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a[2:4] in Dic1.keys():&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; m = Dic1.get(a[2:4])&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; if (a[9] == 's') is True:&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; str1 = 'SUP' + str(int(a[10:15]))&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; else:&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; str1 = 'Inset' + str(int(a[10:15]))&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (a[15] == 's') is True:&lt;/P&gt;&lt;P&gt;&amp;nbsp; str2 = 'Sheet' + str(int(a[16:20]))&lt;/P&gt;&lt;P&gt;&amp;nbsp; str3 = m + ' ' + str(int(a[4:9])) + str1 + str2&lt;/P&gt;&lt;P&gt;&amp;nbsp; return (str3)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working in ArcGIS 9.3&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Padmasiri&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jul 2015 10:09:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/problem-in-field-calculator/m-p/240785#M8204</guid>
      <dc:creator>H_A_D_Padmasiri</dc:creator>
      <dc:date>2015-07-13T10:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in Field Calculator</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/problem-in-field-calculator/m-p/240786#M8205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you have to supply it with a field name as a substitute for 'a'&lt;/P&gt;&lt;P&gt;the function should go in the code block section then the call to the is made in the expression box like&lt;/P&gt;&lt;P&gt;lblcal([yourfield]) if using VB or&amp;nbsp; lblcal(!yourfield!) if using the Python parser&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jul 2015 10:41:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/problem-in-field-calculator/m-p/240786#M8205</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-07-13T10:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem in Field Calculator</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/problem-in-field-calculator/m-p/240787#M8206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In addition to what Dan mentions, you should try and post the post using the instructions found here: &lt;A href="https://community.esri.com/migration-blogpost/1070" target="_blank"&gt;Posting Code blocks in the new GeoNet&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I copied the code and pasted it in an Python IDE and there were issues with the indentation. Apart from that you might be running into an error like "&lt;EM&gt;UnboundLocalError: local variable 'str3' referenced before assignment&lt;/EM&gt;", since str3 only gets assigned in case a[15] is 's'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def lblcal(a):
&amp;nbsp;&amp;nbsp;&amp;nbsp; Dic1 = {'11':'PP', '13':'TOPOPP', '14':'FTP', '15':'VP', '16':'FVP', '17':'CP', '18':'FCP', '19':'FSP', '20':'FSPP', '21':'ISPP', '22':'FUP'}
&amp;nbsp;&amp;nbsp;&amp;nbsp; if a[2:4] in Dic1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m = Dic1[a[2:4]]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a[9] == 's':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; str1 = 'SUP' + str(int(a[10:15]))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; str1 = 'Inset' + str(int(a[10:15]))
&amp;nbsp;&amp;nbsp;&amp;nbsp; if a[15] == 's':
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; str2 = 'Sheet' + str(int(a[16:20]))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; str3 = m + ' ' + str(int(a[4:9])) + str1 + str2
&amp;nbsp;&amp;nbsp;&amp;nbsp; return (str3)&lt;/PRE&gt;&lt;P&gt;This code will probably still generate the error you encounter. What is the error you receive? Does it calculate for some records the values and breaks? Is it possible to provide some values of 'a' to check if it works?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Dic1.keys() can be replace by Dic1&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Dic1.get(a[2:4]) can be replaced by Dic1[a[2:4]]&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;if (a[9] == 's'): is True can be replaced by &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;if a[9] == 's':&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt; if (a[15] == 's') is True: can be replaced by &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt; if a[15] == 's'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;Include at line before line 3 something like: str3 = "Error with: {0}".format(a) to avoid the code to break&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;SPAN&gt;There is no error checking (include try expect to catch errors)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:05:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/problem-in-field-calculator/m-p/240787#M8206</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-11T12:05:52Z</dc:date>
    </item>
  </channel>
</rss>

