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?

6
  • 1
    Can you edit your post to include the field types for each of the 3 fields?
    – Paul
    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?
    – GISHuman
    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.
    – Paul
    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.
    – Geord359
    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?
    – Sleep6
    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

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!

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.