1

I am trying to populate a field with a value from another field in the same row, the condition I have set for this to take place is if a third field is equal to 0. In order to achieve this I have written a python script utilizing an 'if' statement and the getValue and setValue functions. I haven't used these functions before and I am having difficulty getting them to work properly. I tried various different lines of syntax but keep getting the same error:

Runtime error : ERROR 999999: Error executing function.

This has left me a little baffled as I am not sure where the problem lies. Anyway, here's the script:

import arcpy
joinFC = "C:\MyArcGIS\Link_tool\Join22.shp"
rows = arcpy.UpdateCursor(joinFC)
for row in rows:
 if row.getValue("Input") == 0:
 edrn_value = row.getValue("LCC_DRN_3")
 row.setValue("DRN_input", edrn_value)
 rows.updateRow(row)
del row, rows

In case it is not obvious I am using ArcGIS 10.0. The field types for the three fields are:

LCC_DRN_3 = String

Input = Long

DRN_input = String

Does anyone have any idea why this script is not working?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 29, 2014 at 15:23
6
  • 1
    Can you edit your post to include the field types for each of the 3 fields? Commented Jul 29, 2014 at 15:30
  • 1
    what is "edrn_value"? Also I believe this could be achieved in python via the field calculator, is there a reason you're using a standalones script? Commented Jul 29, 2014 at 15:31
  • 1
    Syntactically it should work, so make sure that those are the actual names of the field and not aliases, no locks on the shapefile, etc. Commented Jul 29, 2014 at 15:51
  • Thanks for your suggestions Paul. I'm pretty sure the field names are correct. There is one lock file on the shapefile though, but I'm assuming that is always there when you have the shapefile open. Commented Jul 29, 2014 at 16:09
  • 1
    Are you able to print edrn_value? Are you able to set the value of DRN_input to any other string of your choice? Commented Jul 29, 2014 at 18:21

2 Answers 2

1

Try this

from arcpy import env
d=joinFC.Describe
env.extent=d.extent

Strange but true, if your shapefile is outside processing extent, field calculator will fail on simplest tasks, that have nothing to do with shape field

answered Jul 29, 2014 at 22:06
1

It turns out that the error 999999 was a result of the field I was trying to extract a value from. The attribute table I was working with was the result of a spatial join and the field I used to join the tables was called LCC_DRN_ID. Because you cannot have two identically named fields in the same table the joined features LCC_DRN_ID field became LCC_DRN_3. For whatever reason ArcGIS did not like me using this field, so when I copied the contents of the LCC_DRN_3 field into a newly added field (DRN_update) the following script worked (thanks to Sleep6 for pointing me in the right direction):

import arcpy
joinFC = "C:\MyArcGIS\Link_tool\Join22.shp"
rows = arcpy.UpdateCursor(joinFC)
for row in rows:
 if row.getValue("Input") == 0:
 edrn_value = row.getValue("DRN_update")
 row.setValue("DRN_input", edrn_value)
 rows.updateRow(row)
del row, rows 

Guess I'll have to work an Add Field tool into my overall script!

answered Jul 30, 2014 at 9:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.