Model exported to python script fails with Error 000728

442
2
02-21-2011 11:11 AM
TimothyMichael
Occasional Contributor II
Hello,

I have created a small model that uses three tools - Make Feature Layer, Select Layer by Location, and Export Feature Attribute to ASCII (screenshot is attached). The model works great. I then exported the model to python and tried adding it to a toolbox as a script, which produces an error when run:

Executing: Script "Feature Set"
Start Time: Mon Feb 21 14:59:28 2011
Running script Script...
<class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid.
ERROR 000728: Field PHONE_NUMB does not exist within table
Failed to execute (ExportXYv).

Failed to execute (Script).
Failed at Mon Feb 21 14:59:29 2011 (Elapsed Time: 1.00 seconds)

I am importing the python script unmodified, just as it was exported from Model Builder. I know the field should be there; as a test I stepped through the first part of the script using the Python window, and when the feature layer was created all of the fields were present. The exported script is below; does anyone know what I can do to work around this error?

# ---------------------------------------------------------------------------
# Script5.py
# Created on: 2011-02-21 14:50:53.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: Script5 <Feature_Set> 
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Script arguments
Feature_Set = arcpy.GetParameterAsText(0)
if Feature_Set == '#' or not Feature_Set:
    Feature_Set = "in_memory\\{BF09C0DA-86F6-4FED-962A-77D65E6DC987}" # provide a default value if unspecified

# Local variables:
AddressPoints = "AddressPoints"
Output_Layer_Name = Feature_Set
Test2_txt = Output_Layer_Name
AddressPoints_Layer = "AddressPoints_Layer"

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(AddressPoints, AddressPoints_Layer, "", "", "OBJECTID OBJECTID VISIBLE NONE;Shape Shape VISIBLE NONE;PHONE_NUMB PHONE_NUMB VISIBLE NONE;")

# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(AddressPoints_Layer, "INTERSECT", Feature_Set, "", "NEW_SELECTION")

# Process: Export Feature Attribute to ASCII
arcpy.ExportXYv_stats(Output_Layer_Name, "PHONE_NUMB", "COMMA", Test2_txt, "NO_FIELD_NAMES")




Thanks!
0 Kudos
2 Replies
KarenRobine
Occasional Contributor II
Why dont you use Copy Features to copy the Feature Set to a Feature Class in your scratch workspace. Then, Make the Feature Layer off of that.
0 Kudos
TimothyMichael
Occasional Contributor II
For the purpose of the script I'd rather not generate a temporary feature class on the server.  I did figure out a work around to my problem, though.  I just removed the Output_Layer_Name variable and replaced it with AddressPoints_Layer in ExportXYv_stats process. So the final part now looks like this:

arcpy.ExportXYv_stats(AddressPoints_Layer, "PHONE_NUMB", "COMMA", outputFile, "NO_FIELD_NAMES")


and the script is working properly now, exporting attributes of the selected features.
0 Kudos