I have a script to do a closest facility analysis using Network Analyst. The script works very well until the last line where I want to save the layer as a feature class.
I get an error message.
Excerpt of the script;
###############
print "Solving"
#Solve the closest facility layer
arcpy.na.Solve(layer_object)
# Get the output layer and save it to a feature class
arcpy.management.CopyFeatures(layer_object, outRoutesFC)
#############
This is the error message:
Processing T1 routes
Solving
An error occured on line 85
Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Feature Layer.
ERROR 000840: The value is not a Raster Catalog Layer.
Failed to execute (CopyFeatures).
I will appreciate any help. Thanks.
Dionisio
If you want to save the entire Closest Facility Layer as a layer file, use SaveToLayerFile as Dan suggests. If you just want to save the output Closest Facility routes sublayer to a feature class, you will have to retrieve the sublayer. An example of retrieving and saving sublayers can be found in the last code sample on this page: Make OD Cost Matrix Layer—Help | ArcGIS Desktop
The example is for OD Cost Matrix, but the same principles hold for Closest Facility. Essentially you have to grab the sublayer object and use that in CopyFeatures.