1

I've created a text field, width 255, called BUFFER in the feature class "ForestRoads_Buffer". I want to calculate the BUFFER values of all the features to "Y". The code below doesn't do this and I don't understand what the expression is supposed to look like.

arcpy.CalculateField_management("ForestRoads_Buffer", "BUFFER", "Y", "VB")
  • Are you working from ArcMap and using "ForestRoads_Buffer" as a layer within the MXD? – GeoJohn Jun 6 '17 at 14:44
  • I've run this in the Python window in ArcGIS and get this error message: "Messages Executing: CalculateField ForestRoads_Buffer BUFFER Y VB # Start Time: Tue Jun 06 10:15:36 2017 Empty value for ObjectID = 1 The calculated value is invalid for the row with ObjectID = 1. For example, the calculated value may be too large for the field or you may be trying to add a string to a number field. This row will not be updated." I tried running it in PythonWin 2.7.8 as well without success. – SD Robinson Jun 6 '17 at 14:50
  • What is "Y"? A feature in another layer? Have you tried making BUFFER a float field? – alaybourn Jun 6 '17 at 15:00
  • "Y" is just supposed to be a string of text, denoting "Yes". – SD Robinson Jun 6 '17 at 15:04
  • I believe OPs goal is to have the "BUFFER" field = "Y" for every feature in the FC. – GeoJohn Jun 6 '17 at 15:05
2

You need double quotes around the Y since it's a string. Try:

arcpy.CalculateField_management("ForestRoads_Buffer", "BUFFER", '"Y"', "VB")
  • Ah... Yep that should do it. – GeoJohn Jun 6 '17 at 15:08
  • It's trivial but you can leave out "VB" – jbalk Jun 7 '17 at 4:48

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.