4

I do some script for a shapefile's table.

And this script works for 2 fields and do not for other ones, because of:

ERROR 000728: Field FID_158_01 does not exist within table

But this field is fine and EXIST!

enter image description here

Script executed in field calculator. I take field names from Iterator (Iterate MultiValue).

Expression:

a(!%field_name%!)

Codeblock:

def a(f):
  if f==0:
    z=1
    return z
  elif f==(-1):
    z=0
    return z
  elif f==(1):
    z=1
    return z

Crashlog:

Executing (EXTENT redo math): Model13 H:\TEST\CHECK.shp FID_154_01;FID_153_01;FID_158_01;FID_155_01;FID_153_02
Start Time: Fri Sep 28 14:12:22 2012
Executing (Iterate Multivalue): IterateMultivalue FID_154_01;FID_153_01;FID_158_01;FID_155_01;FID_153_02
Start Time: Fri Sep 28 14:12:23 2012
Succeeded at Fri Sep 28 14:12:23 2012 (Elapsed Time: 0,00 seconds)
Executing (Calculate Field): CalculateField H:\TEST\CHECK.shp FID_154_01 a(!FID_154_01!) PYTHON_9.3 "def a(f):\n  if f==0:\n    z=1\n    return z\n  elif f==(-1):\n    z=0\n    return z\n  elif f==(1):\n    z=1\n    return z"
Start Time: Fri Sep 28 14:12:23 2012
Succeeded at Fri Sep 28 14:12:23 2012 (Elapsed Time: 0,00 seconds)
Executing (Iterate Multivalue): IterateMultivalue FID_154_01;FID_153_01;FID_158_01;FID_155_01;FID_153_02
Start Time: Fri Sep 28 14:12:24 2012
Succeeded at Fri Sep 28 14:12:24 2012 (Elapsed Time: 0,00 seconds)
Executing (Calculate Field): CalculateField H:\TEST\CHECK.shp FID_153_01 a(!FID_153_01!) PYTHON_9.3 "def a(f):\n  if f==0:\n    z=1\n    return z\n  elif f==(-1):\n    z=0\n    return z\n  elif f==(1):\n    z=1\n    return z"
Start Time: Fri Sep 28 14:12:24 2012
Succeeded at Fri Sep 28 14:12:24 2012 (Elapsed Time: 0,00 seconds)
Executing (Iterate Multivalue): IterateMultivalue FID_154_01;FID_153_01;FID_158_01;FID_155_01;FID_153_02
Start Time: Fri Sep 28 14:12:24 2012
Succeeded at Fri Sep 28 14:12:24 2012 (Elapsed Time: 0,00 seconds)
Executing (Calculate Field): CalculateField H:\TEST\CHECK.shp FID_158_01 a(!FID_158_01!) PYTHON_9.3 "def a(f):\n  if f==0:\n    z=1\n    return z\n  elif f==(-1):\n    z=0\n    return z\n  elif f==(1):\n    z=1\n    return z"
Start Time: Fri Sep 28 14:12:25 2012
Failed to execute. Parameters are not valid.
ERROR 000728: Field FID_158_01 does not exist within table
Failed to execute (Calculate Field).
Failed at Fri Sep 28 14:12:25 2012 (Elapsed Time: 0,00 seconds)
Failed to execute (EXTENT redo math).
Failed at Fri Sep 28 14:12:25 2012 (Elapsed Time: 3,00 seconds)

Any ideas?

When i do all the steps in one model it gives me an error.

But when i just make union output file then stop the model and RUN THE SECOND part with field calculations -> error dissapeared and all works fine!!!

8
  • running arcpy under Arcmap seems not very stable, i had some problems like this, i recommend to debug arcpy code under Pyscripter or any python console.
    – geogeek
    Sep 28, 2012 at 8:43
  • 2
    Be careful that you fieldnames don't include any spaces at the end, you cant see it of course, but it will affect the code.
    – U2ros
    Sep 28, 2012 at 10:46
  • 2
    While this may not be the case, I am guessing from the elapsed time using a comma for a decimal separator that your may not be using ANSI characters. If one of your fields has a name that is using non-ANSI characters (UTF for example), it will fail. ESRI has been trying to support UTF characters, but each dBase field name is only 10 bytes (hence the 10 ANSI character field name - read more here). I would suggest checking out if you used UTF characters by accident when creating those fields, or trying in a GDB. Sep 28, 2012 at 15:42
  • 3
    Looks like there is some refresh bug appeared and when u close script shapefile's field names refreshed. Wasted 4 days to discover that shit =(
    – Vasiya
    Oct 1, 2012 at 5:22
  • 1
    This thread mentions the same refresh issue and suggests a manual way to force a refresh but its for .NET, I wonder if there is an equivalent in arcpy. Dec 21, 2012 at 18:02

1 Answer 1

1

Try creating a variable internal to the function. Something like this:

def a(f):
  foo = f
  z=2

  if foo==0:
    z=1
  elif foo == -1:
    z=0
  elif foo==1:
    z=1
  return z

This way you'll also have a clear indication (result is 2) that something went wrong if the field value winds up being something other than 0 or 1. This is one of those things that shouldn't make a difference, but sometimes does because ArcGIS is weird.

It could also be something to do with your selection in the model. If you don't clear your selection, ModelBuilder can do screwy things. So put a "Clear Selection" step in the model as either the first or the last step inside the iteration loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.