1

I'm trying to add a field to a layer file, but it always gives an error. What I did was making a closest facility layer and save the result as a layer and after that I tried to add a field, but then it gives an error. It says it cannot add a field if it isn't a raster layer, ...

I tried to avoid this by making a shapefile (manually) and this can work, but is there a method to do this in Python? So convert a route from the closest facility layer to a shapefile using Python? It always says:

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Feature Layer.

2
  • 5
    You may want to post your actual Python code to help us better troubleshoot your problem.
    – Baltok
    Commented Apr 4, 2013 at 13:39
  • Did you really try to Add Field to a layer file rather than a layer or dataset? If so, that would explain the error message.
    – PolyGeo
    Commented Apr 7, 2013 at 12:46

1 Answer 1

1

You might need to add the ValidateFieldName function to your script, which will replace invalid characters with an underscore, and ensure the suggested new field name does not already exist. The code below should get you started:

import arcpy  
fc = "C:/Data/NameOfData.shp" 
fieldname = arcpy.ValidateFieldName("NewFieldName") 
arcpy.AddField_management(fc, fieldname, "TEXT", "","", 12)

Your Answer

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

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