I started trying to teach myself Python/ArcPy a couple of weeks ago in an attempt to someday be able to convert my plethora of models to more shareable and user-friendly formats (script tools, add-ins, etc.) and it's been going super well so far, but a general topic I am still hung up on is receiving user-defined parameters in my scripts.
Specific example I'm seeking help for: I need a way for the end-user to define stop points based on network junction attributes (my ND has custom junctions) and use those inputs to solve the route. I have scoured the internet for answers and I'm still coming up just short. Here's some sample code of what I think needs to happen. Remember, I'm still super new to this, so there may be some rookie mistakes in this code. Also, I did not complete the code for finding the routes, but included enough to get my point across.
import arcpy, os, datetime, time #check out NA extension arcpy.CheckOutExtension("Network") #set environments - not a real path here, obviously arcpy.env.workspace = arcpy.GetParameterAsText(0) #user selects gdb where network junctions are located Dir = arcpy.env.workspace arcpy.env.overwriteOutput = True #get parameters for stop location selection networkJunctions = arcpy.GetParameterAsText(1) #network junctions feature class stop1 = arcpy.GetParameterAsText(2) #first stop stop2 = arcpy.GetParameterAsText(3) #second stop #define variables expression = " NAME IN ('stop1', 'stop2') " #selection expression date = time.strftime("%d%m%y") outputFCname = Dir + "\\RouteStops" + date #create layer from network junctions FC arcpy.MakeFeatureLayer_management(networkJunctions, "networkJunctions_lyr") #Select the two stops used to solve the route arcpy.SelectLayerByAttribute_management("networkJunctions_lyr", "NEW_SELECTION", expression) #new FC of selected stops arcpy.CopyFeatures_management("networkJunctions_lyr", outputFCname) #solve routes - incomplete arcpy.na.FindRoutes(will worry about this part later)
This code successfully runs up until the FindRoutes part, but there is no output. I have a hunch that I may be making my feature layer at the wrong point in the code, but I've reordered all of this and I still get a new feature class with nothing in it.