AnsweredAssumed Answered

Field Calculator - field values as variables in Pre-Logic Script Code

Question asked by PSArcOnline on Jan 8, 2013
Latest reply on Jan 9, 2013 by PSArcOnline
Hello, i need a litte help. Maybe just a syntax error.

I want to do some little vector math.

Pre-Logic Script Code
import sys def GetVector(shape):   x0 = 1  y0 = 2  x1 = 3  y1 = 4  a = [x0, y0]  b = [x1, y1]  vecsum = [a[0]+b[0], a[1]+b[1] ]  return vecsum[1]


Assignment Code
GetVector( !Shape!)


This works. But i want to use field values, stored in the shape file, for the variables. As one example i tried this:

Pre-Logic Script Code
import sys def GetVector(shape):   x0 = !xorigin!   y0 = 2  x1 = 3  y1 = 4  a = [x0, y0]  b = [x1, y1]  vecsum = [a[0]+b[0], a[1]+b[1] ]  return vecsum[1]


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.

Outcomes