0

I am new in this area. I was practicing the function GetParameterAsText(). I know that when you run the code (for example in PythonWin) it works like the function raw_input(), therefore it should show a small window where the user can input the required fields.

My problem is that I tried yesterday to use the function GetParameterAsText(), but I have this error, and I think it is about the libraries:

I used the example in the ArcGIS Help: http://resources.arcgis.com/en/help/main/10.1/index.html#//018v00000047000000

*File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 322, in RunScript debugger.run(codeObject, main.dict, start_stepping=0) File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\debugger__init__.py", line 60, in run GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 655, in run exec cmd in globals, locals

File "C:\WCGIS\Geog485\Lesson1\scripts\practice_4.py", line 1, in import os

File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 2429, in CopyFeatures raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000735: Input Features: Value is required ERROR 000735: Output Feature Class: Value is required Failed to execute (CopyFeatures).*

  • I think the only way to use GetParameterAsText is via parameters that you configure on the tool dialog by using Add Script on a toolbox. – PolyGeo Feb 8 '15 at 12:22
3

GetParameterAsText works differently (at least in ArcGIS 10). It parses command line arguments passed to the script when it is run so that arcpy.GetParameterAsText(n) returns the same as sys.argv[n+1] (which may be used as well). No interactivity in it.

The only way to give the user a nice window to input the parameters is to create a toolbox in the ArcGIS environment and then Add > Script on it. In the dialog, specify the .py file as the source and declare the parameter names and types plus optional validation.

Then, a script item should appear in the toolbox; double-clicking displays the GUI and lets the user input the parameters. When you click OK, ArcGIS takes the parameters and runs the script with them as command line arguments.

The other way to run the script is to specify the parameters manually in the command line, of course. Not very user-friendly, though, but more useful for debugging, I guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.