1

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

asked Feb 5, 2014 at 19:40

2 Answers 2

5

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%"

answered Feb 5, 2014 at 21:29
0

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")
answered Feb 5, 2014 at 20:04
5
  • 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. Commented Feb 5, 2014 at 20:47
  • you can parse paths with "glob" in Python Commented Feb 5, 2014 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. Commented Feb 5, 2014 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. Commented Feb 5, 2014 at 21:03
  • Stating that things are better done in a different format (e.g. python) is not a useful comment. Switching from one method of creating a tool to another requires a pre-requisite level of skill that may not be present. The question is related to how to get this to work in model builder. Commented Nov 14, 2019 at 11:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.