Thanks Ian.
I guess users of Model Builder should think about upgrading to 10.3 as soon as it is released later in 2014.
Update, the bug above has been rejected in favor of this one. According to the URL, this was apparently found at Beta 10.1 and is marked as fixed in 10.3.
[NIM098729 In ArcGIS for Desktop 10.2.1, when running a model with the Iterate Feature tool, an incorrect number of outputs are generated only when running the model as a tool. ]
Alternate Solution
Instead of running the model as tool, use the Edit window.
1. Right-click the model in ArcCatalog.
2. Navigate to Edit > Validate > Run.
http://support.esri.com/en/bugs/nimbus/role/beta10_1/TklNMDk4NzI5
This is how Ian's workaround works (for the good of the thread, and as a training exercise for me on posting pictures and code in GeoNet).
Here's a picture of my test model. The issue is the value of Output_Name is "%workspace%\%Name%" and the %Name% variable is not getting updated properly for iterations 3..n.
Here's what gets exported:
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# python_iterator_raw.py
# Created on: 2014-07-25 12:26:57.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: python_iterator_raw <workspace> <ascii>
# Description:
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
# Load required toolboxes
arcpy.ImportToolbox("Model Functions")
# Script arguments
workspace = arcpy.GetParameterAsText(0)
if workspace == '#' or not workspace:
workspace = "D:\\Users\\cprice\\work\\test" # provide a default value if unspecified
ascii = arcpy.GetParameterAsText(1)
if ascii == '#' or not ascii:
ascii = "D:\\Users\\cprice\\work\\Iterator_test\\ascii_rasters" # provide a default value if unspecified
# Local variables:
File_txt = workspace
Output_Name = File_txt
Name = workspace
# Process: Iterate Files
arcpy.IterateFiles_mb(ascii, "", "txt", "NOT_RECURSIVE")
# Process: ASCII to Raster
arcpy.ASCIIToRaster_conversion(File_txt, Output_Name, "INTEGER")
And here's the working python script I created from the above
# -*- coding: utf-8 -*-
import arcpy
import os
input_folder = arcpy.GetParameterAsText(0)
output_folder = arcpy.GetParameterAsText(1)
arcpy.env.workspace = input_folder
infiles = arcpy.ListFiles("*.txt")
for f in infiles:
outraster = os.path.splitext(f)[0] # "file.txt" -> "file")
outraster = os.path.join(output_folder, outraster) # add output path
arcpy.ASCIIToRaster_conversion(f, outraster, "INTEGER")
arcpy.AddMessage("Created {}".format(outraster))