0

I would like to run a model that iterates over all feature classes in a feature dataset and uses the feature class name to populate an attribute field (see model below). However, when running the model I get the below error:

enter image description here

Might the problem be in the calculate field expression? It gives me the option to use "Name" from the iterator (hence the arrow connecting name to the calculate field tool). But I can't get the model to run. The resource cited here has not provided much insight.

enter image description here thanks in advance

I also tried to split the models in two (see below). The first one executes no problem. The second gives me the same previous error above.

Adds text field successfully enter image description here

2

Ok, the solution was very simple. Adding double quotes around the %Value% and/or %Name% variable lets model builder recognize the iterator output as an inline variable. So the Calculate field expression that worked was: "%Value%"

1

My guess when I see this error message is that the length of your string is not large enough to store the value of "name". Check in your "Add field" step to make this.

By the way, string manipulation is better done with Python:

import arcpy, glob
arcpy.env.workspace = "your_workspace"
#fcs = arcpy.ListFeatureClasses("*") #get the list of feature classes
fcs = glob.glob("c:\\*\\*.shp") #EDIT
tobemerged = []
for fc in fcs:
    print len(fc) #check for the length of  your name
    arcpy.AddField_management(fc, "name", "TEXT", 150) #length of 50 is usually enough
    arcpy.CalculateField_management(fc, "name", fc, "PYTHON") #[:-4] because I assume that you have a shapefile and remove the extension
    tobemerged.append(fc)
arcpy.Merge_management(tobemerged, "output_feature_class_name")
  • I wanted to use model builder because of the "Parse Path" tool. I have an empty attribute table (OID, SHAPE_Area, SHAPE_Length) and need to populate a field with the name of the feature class. The Iterate Feature Class tool in model builder outputs "Name" that can be used as an inline variable, but the calculate field tool does not pick it up, nor can I add the "%" around the Name to make it a variable. – mikeLdub Feb 5 '14 at 20:47
  • you can parse paths with "glob" in Python – radouxju Feb 5 '14 at 20:54
  • My python is still novice level and I thought using model builder would be much quicker. I'll move to python if I cannot get this model to execute, but would prefer to troubleshoot the model since I can't for the life of me figure out why the calculate field tool fails. – mikeLdub Feb 5 '14 at 21:02
  • see above for the model split in two... the first one executes fine, the second (Calculate Field) fails the same as before. – mikeLdub Feb 5 '14 at 21:03

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.