8

I'm trying to add data to an attribute table in ArcGIS 10 using the following code:

def make_floor_no( shapefile ):
    "Makes header for number of Floors (FLO) and calculates value"

    fieldName = "FLO"
    try:
        ARCPY.AddField_management(shapefile, fieldName, "DOUBLE")
    except:
        print "Field already there"  

    # loop through attribute table    
    Rows = ARCPY.SearchCursor( shapefile ) 

    for row in Rows:
        floors = round( row.getValue( 'HGT' ) / 3.0, 0)
        print str(floors)
        row.setValue( fieldName, floors )
        Rows.updateRow(row)            

However, I keep getting an error along the line

row.setValue( fieldName, floors )

I can't spot anything wrong with this, and have tried a few different options. Is there something wrong with my syntax?

The error message is as follows:

 File "Z:\ConstructionMaterial.py", line 100, in <module> make_floor_no( InputFile )
 File "Z:\ConstructionMaterial.py", line 71, in make_floor_no 
    row.setValue( fieldName, floors )
 File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\arcobjects.py", line 941, in setValue
    return convertArcObjectToPythonObject(self._arc_object.SetValue(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.
9

Search cursors get you read-only rows objects. if you want to update you need to use the update cursor.

So change this

    Rows = ARCPY.SearchCursor( shapefile ) 

To this

    Rows = ARCPY.UpdateCursor( shapefile ) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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