Select to view content in your preferred language

interactive input of values during Python sript processing

2508
1
10-30-2011 09:08 AM
MiroslavKopecky
Deactivated User
I need create script, where user will be interactively insert values. Script will have these processing steps:

1) select input file
2) do some calculations
3) type result of calculations to message window
4) user interactively input value based on results of steps 2 and 3
5) calculation continue

and script MUST be used as tool in ArcMap ToolBox.

For selection of input file I use gp.GetParameterAsText() function and it is ok. For input during script processing I try use raw_input function-it is work in command prompt, but when I use it as script added to toolbox, process is crashed and I get this error message:

<type 'exceptions.EOFError'>: EOF when reading a line

Can someone advise please ?

Example of my code:

import os, string, arcgisscripting, sys
gp=arcgisscripting.create(9.3)
##select input file
in_file=gp.GetParameterAsText(0)
##treshold=gp.GetParameterAsText(2)
##example of calculation
gp.MakeFeatureLayer(in_file, "in_file_lyr")
gp.SelectLayerByAttribute("in_file_lyr","NEW_SELECTION", "\"shape_area\">1500")
count=gp.GetCount_management("in_file_lyr")
##writing results to message window
gp.addMessage("Selected "+str(count))
##input treshold
tresh = raw_input('Please type treshold value: ')##do not work in toolbox, process is crashed in this row
##writing treshold to message window
gp.addMessage("Treshold is "+str(tresh))
##...
##computation continue

Thanks for help.
Miroslav
Tags (2)
0 Kudos
1 Reply
Luke_Pinner
MVP Regular Contributor
Use a GUI toolkit to create a popup input dialog. Tkinter ships with Python, there are also others, wxPython and pyQT for example.

Here is some code to generate an input dialog with Tkinter: http://effbot.org/tkinterbook/tkinter-dialog-windows.htm
0 Kudos