<?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: codeblock...expression won't evaluate variables i.e. --&amp;gt; GetParameterasText in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293644#M22708</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It looks like a scope problem.&lt;BR /&gt;try setting each parameter to a variable using GetParameterAsText outside the expression string, and use the variables inside the string. &lt;BR /&gt;As it stands, you are referenceing a property of the gp inside a tool running in the gp (the gp.GetParameterAsText(n) is not evaluated until it has already been passed as an expression parameter to CalculateField).&lt;BR /&gt;&lt;BR /&gt;to wit:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;param2 = gp.GetParameterAsText(2)
param3 = gp.GetParameterAsText(3)
expression = "autoIncrement(param2, param3)"&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mark,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help. I tried that and it tells me that the variable is not defined(or whatever the verbiage is... I'm at home now and don't have access to my work PC).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your efforts are greatly appreciated; maybe I'm not executing it properly??? (just flailing about at this point).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 14:07:19 GMT</pubDate>
    <dc:creator>kyleturner</dc:creator>
    <dc:date>2021-12-11T14:07:19Z</dc:date>
    <item>
      <title>codeblock...expression won't evaluate variables i.e. --&amp;gt; GetParameterasText</title>
      <link>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293642#M22706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;First, I'm using Arc10, but calling &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;because I am making a script for other users.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the following error when I try to use a codeblock/expression to calculate a field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000539: Error running expression: autoIncrement(gp.GetParameterAsText(2),gp.GetParameterAsText(3)) &amp;lt;type 'exceptions.NameError'&amp;gt;: name 'gp' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (CalculateField).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It seems that I can't pass in variables to my calc field code. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;e.g.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CalculateField_management(FCls30, IDPK, expression, "PYTHON", codeblock)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;where&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;expression = "autoIncrement(gp.GetParameterAsText(2),gp.GetParameterAsText(3))"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I pass in a string for each argument, then no problems.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 14:38:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293642#M22706</guid>
      <dc:creator>kyleturner</dc:creator>
      <dc:date>2012-04-02T14:38:42Z</dc:date>
    </item>
    <item>
      <title>Re: codeblock...expression won't evaluate variables i.e. --&gt; GetParameterasText</title>
      <link>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293643#M22707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It looks like a scope problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;try setting each parameter to a variable using GetParameterAsText outside the expression string, and use the variables inside the string. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As it stands, you are referenceing a property of the gp inside a tool running in the gp (the gp.GetParameterAsText(n) is not evaluated until it has already been passed as an expression parameter to CalculateField).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;to wit:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;param2 = gp.GetParameterAsText(2)
param3 = gp.GetParameterAsText(3)
expression = "autoIncrement(param2, param3)"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:07:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293643#M22707</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2021-12-11T14:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: codeblock...expression won't evaluate variables i.e. --&gt; GetParameterasText</title>
      <link>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293644#M22708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It looks like a scope problem.&lt;BR /&gt;try setting each parameter to a variable using GetParameterAsText outside the expression string, and use the variables inside the string. &lt;BR /&gt;As it stands, you are referenceing a property of the gp inside a tool running in the gp (the gp.GetParameterAsText(n) is not evaluated until it has already been passed as an expression parameter to CalculateField).&lt;BR /&gt;&lt;BR /&gt;to wit:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;param2 = gp.GetParameterAsText(2)
param3 = gp.GetParameterAsText(3)
expression = "autoIncrement(param2, param3)"&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mark,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help. I tried that and it tells me that the variable is not defined(or whatever the verbiage is... I'm at home now and don't have access to my work PC).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your efforts are greatly appreciated; maybe I'm not executing it properly??? (just flailing about at this point).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:07:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293644#M22708</guid>
      <dc:creator>kyleturner</dc:creator>
      <dc:date>2021-12-11T14:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: codeblock...expression won't evaluate variables i.e. --&gt; GetParameterasText</title>
      <link>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293645#M22709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sorry if you know this already, but are you sure you have enough parameters for this? In other words, do you have four parameters - the fourth parameter would be gp.GetParameterAsText(3), not the third?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 18:10:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293645#M22709</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-04-02T18:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: codeblock...expression won't evaluate variables i.e. --&gt; GetParameterasText</title>
      <link>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293646#M22710</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;No worries. I'm very familiar with counting from zero.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks anyways, never hurts to be sure.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 18:14:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/codeblock-expression-won-t-evaluate-variables-i-e/m-p/293646#M22710</guid>
      <dc:creator>kyleturner</dc:creator>
      <dc:date>2012-04-02T18:14:23Z</dc:date>
    </item>
  </channel>
</rss>

