ModelBuilder Error 000732 – How to Fix Iterate Files Tool in ArcGIS

arcpyerror-000732iteratormodelbuilder

I want to use a "simple" iterator to process all the text files in a directory using my model but ModelBuilder won't let me connect the file to the first step of the model. Once I run the Iterate tool, I can connect it to the "Make XY" but then it only runs with the last output of the Iterate tool?

See attached exported image and python code from the tool.

The error 000732 has "In UNIX, a text file cannot be used as an input to a tool with an input table parameter, such as CopyRows or MakeXYEventLayer" but I am using windows.

enter image description here

I have tried %PATH%/%Name%.txt as well.

# ---------------------------------------------------------------------------
# iterate.py
# Created on: 2012-03-12 16:35:41.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Load required toolboxes
arcpy.ImportToolbox("Model Functions")
arcpy.ImportToolbox("P:/2011/Job_237_BushfireHazard_Datasets/Working/post_erratum/ProcessingModels.tbx")


# Local variables:
working = "P:\\2012\\Job_044_DM_Radio_Propogation\\Working\\FinalPropogation\\TRC_Lamb\\Lamb_ModifiedLocation\\working"
v_InFile_ = "%InFile%"
File_txt = "P:\\2012\\Job_044_DM_Radio_Propogation\\Working\\FinalPropogation\\TRC_Lamb\\Lamb_ModifiedLocation\\working\\File.txt"
File2 = "File.txt"
XY_Feature_Class = "%Path%\\%GDB%\\%Name%_pts"
cb_VHN007_1_pts = "%Path%\\%GDB%\\%Name%_pts"
Source = "%Path%\\%GDB%\\%Name%_pts"
Source_Added = "%Path%\\%GDB%\\%Name%_pts"
v_Signal_Strength = "%Path%\\%GDB%\\%Name%_pts"
Signal_Strength_Added_Pts = "%Path%\\%GDB%\\%Name%_pts"
Buffered_tower_range = "%Path%\\%GDB%\\%Name%_buf"
Joined = "%Path%\\%GDB%\\%Name%_join"
Signal_Strength_Added__2_ = "%Path%\\%GDB%\\%Name%_join"
Buffered_tower_range__3_ = "%Path%\\%GDB%\\%Name%_dowgraded"
Layer = "Layer"

# Process: ParseWorkspace
arcpy.ParsePath_mb(working, "FILE")

# Process: Iterate Files
arcpy.IterateFiles_mb(working, "trc_lamb_modifiedLocation_*", "txt", "NOT_RECURSIVE")

# Process: ParseFile
arcpy.ParsePath_mb(File_txt, "FILE")

# Process: ParseName
arcpy.gp.toolbox = "P:/2011/Job_237_BushfireHazard_Datasets/Working/post_erratum/ProcessingModels.tbx";
# Warning: the toolbox P:/2011/Job_237_BushfireHazard_Datasets/Working/post_erratum/ProcessingModels.tbx DOES NOT have an alias. 
# Please assign this toolbox an alias to avoid tool name collisions
# And replace arcpy.gp.ParseName(...) with arcpy.ParseName_ALIAS(...)
arcpy.gp.ParseName(File2)

# Process: Parse Path
arcpy.ParsePath_mb(File_txt, "PATH")

# Process: Copy Features
arcpy.CopyFeatures_management("", XY_Feature_Class, "", "0", "0", "0")

# Process: Delete Field
arcpy.DeleteField_management(XY_Feature_Class, "Best_Unit")

# Process: Add Field (4)
arcpy.AddField_management(cb_VHN007_1_pts, "Source_Ch", "TEXT", "3", "2", "50", "", "NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field (4)
arcpy.CalculateField_management(Source, "Source_Ch", "\"%Name%\"", "PYTHON", "")

# Process: Add Field (2)
arcpy.AddField_management(Source_Added, "SS", "FLOAT", "3", "2", "10", "", "NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field (3)
arcpy.CalculateField_management(v_Signal_Strength, "SS", "re_score(!Rx!,f2)", "PYTHON_9.3", "f2='99'\\ndef re_score(my_field,f2):\\n\\n if (my_field*1) < 14:\\n  f2 = '0'\\n elif (my_field*1) < 24:\\n  f2 = '1'\\n elif (my_field*1) >= 24:\\n  f2 = \"2\"\\n \\n return f2")

# Process: Buffer
arcpy.Buffer_analysis(Signal_Strength_Added_Pts, Buffered_tower_range, "30 Meters", "FULL", "ROUND", "NONE", "")

# Process: Spatial Join
arcpy.SpatialJoin_analysis(Signal_Strength_Added_Pts, Buffered_tower_range, Joined, "JOIN_ONE_TO_ONE", "KEEP_ALL", "Latitude \"Latitude\" true true false 8 Double 0 0 ,First,#,%Path%\\%GDB%\\%Name%_pts,Latitude,-1,-1;Longitude \"Longitude\" true true false 8 Double 0 0 ,First,#,%Path%\\%GDB%\\%Name%_pts,Longitude,-1,-1;Rx \"Rx\" true true false 8 Double 0 0 ,First,#,%Path%\\%GDB%\\%Name%_pts,Rx,-1,-1;Source_Ch \"Source_Ch\" true true false 50 Text 0 0 ,First,#,%Path%\\%GDB%\\%Name%_pts,Source_Ch,-1,-1;SS \"SS\" true true false 4 Float 0 0 ,First,#,%Path%\\%GDB%\\%Name%_pts,SS,-1,-1;SS_1 \"SS\" true true false 4 Float 0 0 ,First,#,%Path%\\%GDB%\\%Name%_buf,SS,-1,-1", "WITHIN", "30 Meters", "")

# Process: Add Field (3)
arcpy.AddField_management(Joined, "Downgraded_SS", "FLOAT", "3", "2", "10", "", "NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field (2)
arcpy.CalculateField_management(Joined, "Downgraded_SS", "re_score(!SS!, !SS_1!)", "PYTHON", "def re_score(f1,f2):\\n    if f1 < f2:\\n        out1 = f1\\n    else:\\n        out1 = f2\\n    return out1")

# Process: Buffer (3)
arcpy.Buffer_analysis(Signal_Strength_Added__2_, Buffered_tower_range__3_, "30 Meters", "FULL", "ROUND", "LIST", "Downgraded_SS")

# Process: Make XY Event Layer (2)
arcpy.MakeXYEventLayer_management(v_InFile_, "", "", Layer, "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119521E-09;0.001;0.001;IsHighPrecision", "")

Best Answer

Assuming that your text files are some sort of tables (e.g. CSV having X and Y coordinates in rows with delimited columns), try using 'Iterate Tables' instead of 'Iterate Files'. You will be offered an option of choosing DBF or INFO as the type. Ignore this field. It is optional. You should now be able to connect the output file to the 'Make XY Event Layer' tool.

You have included a heap of Python code in this post. Remember that the 'Export to Python Script' option in Model Builder will not include the iterator. If you want a Python script, then you will have to write this yourself.

Related Question