I am trying to iterate a series of feature classes (polygons) in model builder to convert a series of polygons to rasters, however, I am having an issue with the output file names.

After inserting the "iterate feature class" tool into the model builder window, and linking my gdb storing all the polygons as the input, the output feature (green bubble) automatically becomes the name of my first polygon. As a result the model that I attempt to run seems to recur to that named polygon rather than then going to the next polygon in the list. Output rasters are created, but overwrite that file name rather than generating a new raster with a new name that matches the subsequent polygons.

What am I doing wrong?

4 Answers 4


Here is the model, it uses inline substitution as described by Aaron. Note the output of the Polygon to raster tool is ..\fGBD_Scratch.gdb\ras_%Value%. Value is coming from the iterator which in this case was set to FID to hand out unique rows. So the first raster dataset would be ras_1, then ras_2, etc.


  • Do you simply add the "%" on either side of the name inserted in the output? for example %name%_clip?
    – macdonaw
    Apr 14, 2015 at 17:53
  • Yes, so in your example 'name' is an variable in your model, typically something from an iterator.
    – Hornbydd
    Apr 14, 2015 at 22:53
  • 1
    Yes, but your name should not start with % sign... use it in reverse order, i.e. clip_%Name%
    – maycca
    Apr 7, 2017 at 8:33

There are several ways to deal with naming in model builder. ArcGIS has a help section on this: A quick tour of using inline variable substitution.

One slick way to quickly create unique names from an iterator is by calling the %i% or %n% system variables, which output files in the following form: file1, file2, file3, file4... The %i% system variable references the current list position, while the %n% system variable references the current model iteration. You would put this into practice in the output parameter of a tool you are using. For example:

Output Feature Class


It sounds like you want to do a couple of nested loops, one for the feature classes in a workspace, and one for the features in each feature class. This is painful (but possible) to do with ModelBuilder.

If you want to get your hands dirty with Python (which I definitely recommend for stuff like this), here is an example to get you started:

import arcpy, os

# Your source file geodatabase
input_workspace = r"c:\GISData\input.gdb"

# Your output raster folder
output_workspace = r"c:\GISData\rasters"

# The file extension for the output rasters -- when not saving to a geodatabase, specify .tif for a TIFF file format, .img for an ERDAS IMAGINE file format, or no extension for a GRID raster format.
output_ext = ".img"

# The field used to assign values to the output raster -- hopefully this is the same for all of your feature classes
value_field = "VALUE"

# Note: Instead of hardcoding the above values, you could also use arcpy.GetParameterAsText to allow the user to specify them via script tool parameters

# Set current workspace to the source file geodatabase
arcpy.env.workspace = input_workspace

# Loop over the feature classes
for fc in arcpy.ListFeatureClasses():

  # Get the name of the ObjectID field so we can use it to name the output rasters
  oid_field = arcpy.Describe(fc).OIDFieldName

  # Loop over the features in the current feature class
  for row in arcpy.SearchCursor(fc):

    # Figure out what to name the output raster. In this case we should get something like "c:\GISData\rasters\myFeatureClass_1.img"
    out_raster = os.path.join(output_workspace, "{0}_{1}{2}".format(os.path.basename(fc), row.getValue(oid_field), output_ext))

    # Convert to raster
    arcpy.PolygonToRaster_conversion(row, value_field, out_raster)

Untested, but hopefully you get the idea. IMO, Python scripts are much easier to work with than ModelBuilder models for all but the most trivial of tasks.

For Python/ArcPy learning resources, look no further than this question: What are some resources for learning ArcPy?

  • Nested loops in model builder are misery. Avoid if possible.
    – Mox
    Jan 19, 2020 at 19:51

Updating these answers with a way to do this if you want to stay in model builder, and name your output files with a meaningful field value, rather than just the iterator number. Output paths and files can be renamed using the "Get Field Value" tool.

In your model use Insert > Model Only Tools > "Get Field Value" (GFV). I suggest renaming the output from GFV to "name" or something else that differentiates it from the counter value output from the "Iterate Feature Selection" (IFS) tool. Otherwise both will be names "value" or "value 2" etc and it is very easy to get them mixed up.

Once it is renamed, use the output from the GFW as a variable in your path e.g. C:\Users[user]\Documents\ArcGIS\Default.gdb%Name%

You may also want to set the GFW output as a precondition to Polygon to Raster (or any other tool that you would like to use that value in the name or path.

capture of the tools described

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.