<?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: Field Calculator - field values as variables in Pre-Logic Script Code in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-calculator-field-values-as-variables-in-pre/m-p/62476#M5046</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, that did the trick.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 Jan 2013 09:58:07 GMT</pubDate>
    <dc:creator>PSArcOnlinePSArcOnline</dc:creator>
    <dc:date>2013-01-09T09:58:07Z</dc:date>
    <item>
      <title>Field Calculator - field values as variables in Pre-Logic Script Code</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-field-values-as-variables-in-pre/m-p/62474#M5044</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello, i need a litte help. Maybe just a syntax error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to do some little vector math.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Pre-Logic Script Code&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import sys def GetVector(shape):&amp;nbsp;&amp;nbsp; x0 = 1&amp;nbsp; y0 = 2&amp;nbsp; x1 = 3&amp;nbsp; y1 = 4&amp;nbsp; a = [x0, y0]&amp;nbsp; b = [x1, y1]&amp;nbsp; vecsum = [a[0]+b[0], a[1]+b[1] ]&amp;nbsp; return vecsum[1]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Assignment Code&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;GetVector( !Shape!)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works. But i want to use field values, stored in the shape file, for the variables. As one example i tried this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Pre-Logic Script Code&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import sys def GetVector(shape):&amp;nbsp;&amp;nbsp; x0 = !xorigin!&amp;nbsp;&amp;nbsp; y0 = 2&amp;nbsp; x1 = 3&amp;nbsp; y1 = 4&amp;nbsp; a = [x0, y0]&amp;nbsp; b = [x1, y1]&amp;nbsp; vecsum = [a[0]+b[0], a[1]+b[1] ]&amp;nbsp; return vecsum[1]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;which gives a syntax error. What is wrong? In the Shape file there is a field named "xorigin" (type double) with a value of 3773506,87592.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jan 2013 10:51:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-field-values-as-variables-in-pre/m-p/62474#M5044</guid>
      <dc:creator>PSArcOnlinePSArcOnline</dc:creator>
      <dc:date>2013-01-08T10:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator - field values as variables in Pre-Logic Script Code</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-field-values-as-variables-in-pre/m-p/62475#M5045</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You have to pass it from the calculation expression as a variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def GetVector(shape, xorigin): &amp;nbsp;&amp;nbsp;&amp;nbsp; x0 = xorigin &amp;nbsp;&amp;nbsp;&amp;nbsp; y0 = 2 &amp;nbsp;&amp;nbsp;&amp;nbsp; x1 = 3 &amp;nbsp;&amp;nbsp;&amp;nbsp; y1 = 4 &amp;nbsp;&amp;nbsp;&amp;nbsp; a = [x0, y0] &amp;nbsp;&amp;nbsp;&amp;nbsp; b = [x1, y1] &amp;nbsp;&amp;nbsp;&amp;nbsp; vecsum = [a[0] + b[0], a[1] + b[1]] &amp;nbsp;&amp;nbsp;&amp;nbsp; return vecsum[1]&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;GetVector(!Shape!, !xorigin!)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jan 2013 12:27:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-field-values-as-variables-in-pre/m-p/62475#M5045</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2013-01-08T12:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calculator - field values as variables in Pre-Logic Script Code</title>
      <link>https://community.esri.com/t5/python-questions/field-calculator-field-values-as-variables-in-pre/m-p/62476#M5046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, that did the trick.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jan 2013 09:58:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-calculator-field-values-as-variables-in-pre/m-p/62476#M5046</guid>
      <dc:creator>PSArcOnlinePSArcOnline</dc:creator>
      <dc:date>2013-01-09T09:58:07Z</dc:date>
    </item>
  </channel>
</rss>

