2

I am running a script which takes some input parameters and runs some Network Analyst processes. The script is imported into a toolbox and is setup in Model Builder with the necessary input and output parameters.

My problem is that I am struggling to understand how to get the resulting Solve operation back out of the script and into Model Builder for subsequent work.

Here is my script:

# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("Network")

# Script arguments
Network_Dataset = arcpy.GetParameterAsText(0) # Network dataset layer

Input_Locations = arcpy.GetParameterAsText(1) # Layer file

Output_Path = arcpy.GetParameterAsText(2) # Output path

# Local variables:
#Solve_Succeeded = Network_Analyst_Layer__3_
#Output_derived_feature_class = Network_Dataset

arcpy.AddMessage("Creating the Origin Destination layer...")

# Process: Make OD Cost Matrix Layer
arcpy.MakeODCostMatrixLayer_na(Network_Dataset, "odMatrix", "Length", "100", "", "", "ALLOW_UTURNS", "", "", "", "NO_LINES", "")

arcpy.AddMessage("Calculating Locations. This may take a while...")

# Process: Calculate Locations
arcpy.CalculateLocations_na(Input_Locations, Network_Dataset, "500 Meters", [["Streets","SHAPE"],["Streets_ND_Junctions","NONE"]] , "MATCH_TO_CLOSEST", "", "", "", "", "", "", "", "", "", "INCLUDE", "")

arcpy.AddMessage("Adding locations to Origin Destination layer...")

# Process: Add Locations to Origins Sub-Layer
arcpy.AddLocations_na("odMatrix", "Origins", Input_Locations, "", "500 Meters", "", "", "MATCH_TO_CLOSEST", "APPEND", "", "", "INCLUDE", "")

# Process: Add Locations to Destinations Sub-Layer
arcpy.AddLocations_na("odMatrix", "Destinations", Input_Locations, "", "500 Meters", "", "", "MATCH_TO_CLOSEST", "APPEND", "", "", "INCLUDE", "")

arcpy.AddMessage("Starting Network Analysis solve...")

# Process: Solve
arcpy.Solve_na("odMatrix", "SKIP", "TERMINATE", "")

arcpy.AddMessage("Network analysis completed.")

# How to get this out of script???

# Return as model output parameter
arcpy.SetParameterAsText(3, outputTable)
1
  • 1
    Pity you are on 10.0. In 10.1 and above, you could use: naClasses = arcpy.na.GetNAClassNames(serviceAreaLayer) >> arcpy.na.Solve(serviceAreaLayer) >> polygonsSublayer = arcpy.mapping.ListLayers(serviceAreaLayer,naClasses["SAPolygons"])[0] Commented Jan 7, 2014 at 14:12

1 Answer 1

3

You can save the result as a layer filer with this command

arcpy.management.SaveToLayerFile("odMatrix",Output_Path)

after : arcpy.Solve_na("odMatrix", "SKIP", "TERMINATE", "")

where Output_Path must be the path to a lyr file.

we can find more informations here :

http://resources.arcgis.com/fr/help/main/10.1/index.html#//00480000000r000000

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.