Select to view content in your preferred language

Parameters in Python script

4288
10
10-29-2015 07:22 AM
TerryGustafson
Frequent Contributor

I'm trying to figure out parameters in python.  I created a model and it has some parameters in it.  When I run it and create a GP service from it, it asks me to enter those parameters and then runs.  I have a python script that I added to a toolbox hoping it would ask for those parameters as well.  when I add the script to the toolbox and run it, it says this tool has no parameters.  I assumed the in the script arguments from my example that the first_point = arcpy.GetParametersAsText(0) would ask me to enter the first point.  Can someone point me in the right direction?  TIA

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# new_seg4.py
# Created on: 2015-10-29 07:32:00.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: new_seg4 <first_point> <end_point> <first_point__2_> <end_point__3_> <beg_point> <end_pt> <first_pt_loc> <end_pt_loc> <points> <segment> <temp__2_> 
# Description: 
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
arcpy.env.overwriteOutput = True
toolbox = ("E:/MDTAPPS/interactive/refmseg.tbx")
# Load required toolboxes
arcpy.ImportToolbox("E:/MDTAPPS/interactive/refmseg.tbx")
# Script arguments
first_point = arcpy.GetParameterAsText(0)
if first_point == '#' or not first_point:
    first_point = "E:\\MDTAPPS\\interactive\\interactive.mdb\\first_point" # provide a default value if unspecified
end_point = arcpy.GetParameterAsText(1)
if end_point == '#' or not end_point:
    end_point = "E:\\MDTAPPS\\interactive\\interactive.mdb\\end_point" # provide a default value if unspecified
first_point__2_ = arcpy.GetParameterAsText(2)
if first_point__2_ == '#' or not first_point__2_:
    first_point__2_ = "E:\\MDTAPPS\\interactive\\interactive.mdb\\first_point" # provide a default value if unspecified
end_point__3_ = arcpy.GetParameterAsText(3)
if end_point__3_ == '#' or not end_point__3_:
    end_point__3_ = "E:\\MDTAPPS\\interactive\\interactive.mdb\\end_point" # provide a default value if unspecified
beg_point = arcpy.GetParameterAsText(4)
if beg_point == '#' or not beg_point:
    beg_point = "beg_point" # provide a default value if unspecified
end_pt = arcpy.GetParameterAsText(5)
if end_pt == '#' or not end_pt:
    end_pt = "end_pt" # provide a default value if unspecified
first_pt_loc = arcpy.GetParameterAsText(6)
if first_pt_loc == '#' or not first_pt_loc:
    first_pt_loc = "E:\\MDTAPPS\\interactive\\interactive.mdb\\first_pt_loc" # provide a default value if unspecified
end_pt_loc = arcpy.GetParameterAsText(7)
if end_pt_loc == '#' or not end_pt_loc:
    end_pt_loc = "E:\\MDTAPPS\\interactive\\interactive.mdb\\end_pt_loc" # provide a default value if unspecified
points = arcpy.GetParameterAsText(8)
if points == '#' or not points:
    points = "E:\\MDTAPPS\\interactive\\interactive.mdb\\points" # provide a default value if unspecified
segment = arcpy.GetParameterAsText(9)
if segment == '#' or not segment:
    segment = "segment" # provide a default value if unspecified
temp__2_ = arcpy.GetParameterAsText(10)
if temp__2_ == '#' or not temp__2_:
    temp__2_ = "E:\\MDTAPPS\\interactive\\interactive.mdb\\temp" # provide a default value if unspecified
# Local variables:
Output_Event_Table_Properties = "RID POINT MEAS"
Output_Event_Table_Properties__2_ = "RID POINT MEAS"
MDTGIS_ROUTES_LRM_RM = "MDTGIS.ROUTES_LRM_RM"
MDTGIS_ROUTES_LRM_DC_MI = "MDTGIS.ROUTES_LRM_DC_MI"
MDTGIS_ROUTES_LRM_DC_MI__2_ = "MDTGIS.ROUTES_LRM_DC_MI"
interactive_mdb = "E:\\MDTAPPS\\interactive\\interactive.mdb"
MDTGIS_ROUTES_LRM_DC = "MDTGIS_ROUTES_LRM_DC"
temp = "E:\\MDTAPPS\\interactive\\interactive.mdb\\temp"
# Process: Calculate Field
arcpy.CalculateField_management(first_point, "Corridor", "str(!Corridor!) + \"_\" + str(!RM!)", "PYTHON_9.3", "")
# Process: Calculate Field (2)
arcpy.CalculateField_management(end_point, "Corridor", "str(!Corridor!) + \"_\" + str(!RM!)", "PYTHON_9.3", "")
# Process: Make Route Event Layer (2)
arcpy.MakeRouteEventLayer_lr(MDTGIS_ROUTES_LRM_RM, "ROUTE_ID", end_point__3_, "Corridor POINT end_offset", end_pt, "", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
# Process: Make Route Event Layer
arcpy.MakeRouteEventLayer_lr(MDTGIS_ROUTES_LRM_RM, "ROUTE_ID", first_point__2_, "Corridor POINT beg_offset", beg_point, "", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
# Process: Locate Features Along Routes
arcpy.LocateFeaturesAlongRoutes_lr(beg_point, MDTGIS_ROUTES_LRM_DC_MI, "CORRIDOR", "0 Meters", first_pt_loc, Output_Event_Table_Properties, "ALL", "NO_DISTANCE", "ZERO", "NO_FIELDS", "NO_M_DIRECTION")
# Process: Locate Features Along Routes (2)
arcpy.LocateFeaturesAlongRoutes_lr(end_pt, MDTGIS_ROUTES_LRM_DC_MI__2_, "CORRIDOR", "0 Meters", end_pt_loc, Output_Event_Table_Properties__2_, "FIRST", "NO_DISTANCE", "ZERO", "NO_FIELDS", "NO_M_DIRECTION")
# Process: Append
arcpy.Append_management("E:\\MDTAPPS\\interactive\\interactive.mdb\\first_pt_loc;E:\\MDTAPPS\\interactive\\interactive.mdb\\end_pt_loc", temp, "", "RID \"CORRIDOR\" true true false 10 Text 0 0 ,First,#,E:\\MDTAPPS\\interactive\\interactive.mdb\\first_pt_loc,RID,-1,-1,E:\\MDTAPPS\\interactive\\interactive.mdb\\end_pt_loc,RID,-1,-1;beg_offset \"beg_offset\" true true false 8 Double 0 0 ,First,#;end_offset \"end_offset\" true true false 8 Double 0 0 ,First,#", "")
# Process: Table to Table
arcpy.TableToTable_conversion(temp__2_, interactive_mdb, "points", "", "RID \"CORRIDOR\" true true false 10 Text 0 0 ,First,#,E:\\MDTAPPS\\interactive\\interactive.mdb\\temp,RID,-1,-1;beg_offset \"beg_offset\" true true false 8 Double 0 0 ,First,#,E:\\MDTAPPS\\interactive\\interactive.mdb\\temp,beg_offset,-1,-1;end_offset \"end_offset\" true true false 8 Double 0 0 ,First,#,E:\\MDTAPPS\\interactive\\interactive.mdb\\temp,end_offset,-1,-1", "")
# Process: Make Route Event Layer (3)
arcpy.MakeRouteEventLayer_lr(MDTGIS_ROUTES_LRM_DC, "CORRIDOR", points, "rid LINE beg_offset end_offset", segment, "", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
# Process: Script1
arcpy.Script1_ref()
0 Kudos
10 Replies
JamesCrandall
MVP Alum

I really do not have an understanding of what you are trying to do with your script.  I'd suggest you strip out as much as possible, simplifying things down to bare necessities that accomplishes a portion or a simplified version of what you expect.  Then build upon what you learn from that.

0 Kudos