4

I am using ArcGIS 10.2 ModelBuilder with the Field Values iterator to select unique field values. I then want to forward these values to the Add Field tool, to create a new field for each unique value.

The problem I have is that the iterator's output value appears to have a temporary starter value of "1" by default, which is then replaced by the actual values once the model runs. However, the issue is that the Add Field tool throws an error before the model even starts, because it cannot use numbers as inputs for field names, so it remains out of action once the "real" values become available.

How fo I flush-out or replace this starting value of "1"?

The Iterate Field Values tool is correctly set to "String" data type, yet the temporary starter / filler value remains "1".

I've attached a picture of my model and submodel.


I was unable to get it working in ModelBuilder, it is presumably a bug. But I was successful in getting it working via a python script along the lines of the answer listed below.

Sub-model called "sifter" Model

2 Answers 2

2

This is not exactly the answer you are looking for, but you could use "pivot table" to do what you want.

Concerning ModelBuilder problem, take a look at the type of input. For instance, you will not be able to create a field based on a value that is not of type "text", and some characters are not allowed in the name of the fields (depending on the type of output data)


Using Python, you can use the search cursor

import arcpy
rows = arcpy.SearchCursor(yourfeatureclass)
for row in rows:
   try:
        arcpy.AddField_management(yourfeatureclass, str(row.getValue("yourfield"), "LONG")
   except:
        print "field already exists" 
3
  • Thanks for the input. I am trying to use only unique field values to create new fields, so I'm not sure that the pivot table will work. (Unless I haven't figured it out.) Regarding the field type, I suspect that this is what is causing the error because when I setup the model it generates a temporary value of "1" in the output field from the iterator, which prompts a warning error for the input to Add Field...even though I have all of the relevant field type boxes correct. Not sure if there is a way to override this.
    – songololo
    Jan 6, 2014 at 9:27
  • My best advice is to switch from ModelBuilder to Python. You can start by exporting your model to a Python script. In Python, you can easily change the type from "integer" to "string" using str().
    – radouxju
    Jan 6, 2014 at 10:05
  • The problem appears to be as a result of a numeric starter value on the output of the iterator, which is then rejected by the Add Field tool. I've updated my original question accordingly.
    – songololo
    Jan 6, 2014 at 10:06
1

This issue can be overcome in ModelBuilder using inline variable substitution - instead of passing the value from the iterator directly to the Add Field tool, use %Value% as the field name in the Add Field tool.

Your Answer

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

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