GetParameterAsText  "ERROR 000735: Input Features: Value is required"

4147
6
11-29-2011 08:18 PM
darylejohnson
New Contributor
I cannot get this code to work. It is a simple homework assignment- I saw a similar post that I quote below but my problem is slightly different as I wrote the code as script not exported from a model :

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 cannot get the box to come up asking the user to choose which featureclass to run the script/model on or the output file etc.
Previous poster added the script as a tool and made parameters there but I need to code them from script for this homework- the script works if I hardcode the inputs.

    CODE:
# Purpose: Copy selected features from one feature class into
#          a brand new feature class.

# Import the arcpy module
import arcpy, os.path

# Input feature class.
inFC = arcpy.GetParameterAsText(0)
# Output feature class.
outFC = arcpy.GetParameterAsText(1)
# SQL statement to filter features. If the expression is empty,
# all features will be copied into the new feature class.
expression = arcpy.GetParameterAsText(2)
# Field information to alter output fields. If the fieldInfo
# is empty, all fields will be unaltered in the new feature class.
fieldInfo = arcpy.GetParameterAsText(3)

# Make a temporary layer to hold the selected features and altered fields.
# The selected features are determined by the expression variable.
# The altered fields are determined by the fieldInfo variable.
arcpy.MakeFeatureLayer_management(inFC, os.path.basename(outFC), expression,
                               os.path.dirname(outFC), fieldInfo)

# Copy selected features and altered fields to the output feature class.
arcpy.CopyFeatures_management(os.path.basename(outFC), outFC)
Tags (2)
0 Kudos
6 Replies
darylejohnson
New Contributor
PS- This script works fine from the windows command prompt like so :




C:\Python26\ArcGIS10.0>python c:\usr\myname\lab12\test\fc2fc.py c:\usr\myname\la
b10\world\world\rivers.shp c:\usr\myname\lab12\test\rivers.shp "" ""

C:\Python26\ArcGIS10.0>
0 Kudos
MathewCoyle
Frequent Contributor
You have to add your script as a script tool if you want any kind of interactivity with user input, outside of command line parameters as you have already seen. If you do not add your script as a script tool, nothing will pop up asking you to choose anything, unless you design your own GUI to do so.
0 Kudos
RuthEmerick
New Contributor II
You should also check out sys.argv for user input.
0 Kudos
darylejohnson
New Contributor
Thanks guys - but are you sure about that ? I have a video demo of my teaching assistant writing that code manually and running it from pythonwin and an input box pops up- I am brand new to python and arcgis so not disputing you guys but I see it happening so just wondering. Here are our homework instructions directing us to do it that way also :

Step 2: Replace Hard Coded Values With Dynamic Values
Replace the hard-coded values with the arcpy.GetParameterAsText() function.
�?� Save the FC2FC_HardCoded.py script to C:\usr\yourname\lab12\FC2FC.py.
import arcpy, os.path
�?� Modify the following variables to accept user-specified input.
inFC = arcpy.GetParameterAsText(0)
outFC = arcpy.GetParameterAsText(1)
expression = arcpy.GetParameterAsText(2)
fieldInfo = arcpy.GetParameterAsText(3)
�?� Save the script.


He does this manually in the video and immediately runs the script- I will see if I can post a screen shot
0 Kudos
MathewCoyle
Frequent Contributor
There is no way to code a pop up window without import a gui module like tkinter. He may be using a simple run with parameters button, which is just an option in most moderately advanced python IDEs, and has nothing to do with your code.
0 Kudos
RuthEmerick
New Contributor II
Thanks guys - but are you sure about that ? I have a video demo of my teaching assistant writing that code manually and running it from pythonwin and an input box pops up- I am brand new to python and arcgis so not disputing you guys but I see it happening so just wondering. Here are our homework instructions directing us to do it that way also :

Step 2: Replace Hard Coded Values With Dynamic Values
Replace the hard-coded values with the arcpy.GetParameterAsText() function.
�?� Save the FC2FC_HardCoded.py script to C:\usr\yourname\lab12\FC2FC.py.
import arcpy, os.path
�?� Modify the following variables to accept user-specified input.
inFC = arcpy.GetParameterAsText(0)
outFC = arcpy.GetParameterAsText(1)
expression = arcpy.GetParameterAsText(2)
fieldInfo = arcpy.GetParameterAsText(3)
�?� Save the script.


He does this manually in the video and immediately runs the script- I will see if I can post a screen shot


PythonWin does have a popup for user input for input and raw_input--I haven't used the arcpy GetParameter functions with PythonWin, but I have used the other with it. You could try this:

inFC = raw_input("Please enter parameter 0: ")
outFC = raw_input("Please enter parameter 1: ")
expression = raw_input("Please enter parameter 3: ")
fieldInfo = raw_input("Please enter parameter 4: ")
0 Kudos