bobby_saleh

How can I successfully use GetParameterAsText in ArcPy?

Discussion created by bobby_saleh on Jun 9, 2011
Latest reply on Jun 23, 2011 by lpugh01
I cannot get this code to work. Admittedly, I am new to programming with ArcPy.

I am trying to use the GetParameterAsText to ask the user to give input (to let them choose which featureclass they want to use) from the script. I keep getting the message : "Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000735: Input Features: Value is required"

I built this using Model Builder and then exported the model to python to look at the code to start customizing what I want it to do. I cannot get the box to come up asking the user to choose which featureclass to run the script/model on.


[INDENT]CODE:
import arcpy

print "Start time = " + time.asctime()

# Script arguments
Expression = arcpy.GetParameterAsText(0)
if Expression == '#' or not Expression:
Expression = "\"Segment_ID\" In ('C1', 'C2', 'C3', 'C4', 'C5')" # provide a default value if unspecified
Input_Features = arcpy.GetParameterAsText(1)

# Local variables:
Test = Expression
Test_UnsplitLine = Test
ROUTE_FINAL = Test_UnsplitLine
ROUTE_FINAL__2_ = ROUTE_FINAL
Route_Real_OUTPUT_gdb = "G:\\40\\Scratch\\Real_OUTPUT.gdb"

# Process: Feature Class to Feature Class
tempEnvironment0 = arcpy.env.scratchWorkspace
arcpy.env.scratchWorkspace = "G:\\40\\Scratch\\Route_Scratch_Work.gdb"
empEnvironment1 = arcpy.env.outputCoordinateSystem
arcpy.env.outputCoordinateSystem = "PROJCS['NS_Equidistant_Conic',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Equidistant_Conic'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-154.0],PARAMETER['Standard_Parallel_1',68.0],PARAMETER['Standard_Parallel_2',74.0],PARAMETER['Latitude_Of_Origin',40.0],UNIT['Foot_US',0.3048006096012192]]"
tempEnvironment2 = arcpy.env.geographicTransformations
arcpy.env.geographicTransformations = "NAD_1983_To_WGS_1984_1"
tempEnvironment3 = arcpy.env.workspace
arcpy.env.workspace = "G:\\40\\Scratch\\Route_Scratch_Work.gdb"
arcpy.FeatureClassToFeatureClass_conversion(Input_Features, Real_OUTPUT_gdb, "Test", Expression, "", "")
arcpy.env.scratchWorkspace = tempEnvironment0
arcpy.env.outputCoordinateSystem = tempEnvironment1
arcpy.env.geographicTransformations = tempEnvironment2
arcpy.env.workspace = tempEnvironment3
# Process: Unsplit Line
arcpy.UnsplitLine_management(Test, Test_UnsplitLine, "Segment_ID", "")
# Process: Create Routes
arcpy.CreateRoutes_lr(Test_UnsplitLine, "Segment_ID", ROUTE_FINAL, "LENGTH", "", "", "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
# Process: Add Field
arcpy.AddField_management(ROUTE_FINAL, "RID", "TEXT", "", "", "70", "", "NULLABLE", "NON_REQUIRED", "")

print "End Time =" + time.asctime()[/INDENT]


I think that showing all of this code is a bit overwhelming - I really just need to know how to call a user interface box to ask the user to choose which featureclass to perform the model on.

Any help is greatly appreciated!
Bobby

Outcomes