+ Reply to Thread
Results 1 to 18 of 18

Thread: Get user input text in arcpy

  1. #1
    William Ide
    Join Date
    Nov 2011
    Posts
    48
    Points
    2
    Answers Provided
    0


    0

    Default Get user input text in arcpy

    I want to ask the user what name to give to a report. I could use Tkinter to do this but it seem there should be something in arcpy to do it. Just pop up a little dialog ask for some text and return that text as a string. Is there something like that?

    Thanks.

  2. #2
    Joel Calhoun
    Join Date
    Apr 2010
    Posts
    133
    Points
    32
    Answers Provided
    2


    0

    Default Re: Get user input text in arcpy

    You could easily do that in a script tool, but I'm not sure of your workflow.


    Joel

  3. #3
    Nobbir Ahmed

    Join Date
    Jun 2010
    Posts
    327
    Points
    124
    Answers Provided
    17


    0
    This post is marked as the answer

    Default Re: Get user input text in arcpy

    Use raw_input to get user input in command line:

    Code:
    in_txt = raw_input('Enter your value :')

  4. #4
    William Ide
    Join Date
    Nov 2011
    Posts
    48
    Points
    2
    Answers Provided
    0


    0

    Default Re: Get user input text in arcpy

    To be clear. I want a dialog by that pops up and asked the user to enter some text and press OK. Then I return the the main program and use the text create a report heading. raw_input gave me an error "EOF found while reading."

  5. #5
    Jason Scheirer

    Join Date
    Oct 2009
    Posts
    513
    Points
    485
    Answers Provided
    68


    0

    Default Re: Get user input text in arcpy

    This isn't supported from ArcMap directly, the way for Python to interact with the user in the desktop environment is through GP tool dialogs. That is, write it as a script tool with the report name as a parameter.

  6. #6
    Nobbir Ahmed

    Join Date
    Jun 2010
    Posts
    327
    Points
    124
    Answers Provided
    17


    1

    Default Re: Get user input text in arcpy

    If you really want a pop-up dialog you can create a script tool. For your convenience I'm attaching a python script tool as a zip file.

    When unzipped, you'll see following files there:

    PopUp.tbx - a toolbox containing a script too and a Model.
    pop_up_script - the source script of the tool.
    calling_script - how to call the tool from another stand-alone script.
    python_window.txt - how to call the tool from Python window.

    In ArcMap, browse to the location of the toolbox (unzipped folder). From the toolbox open the script tool - whatever text value you enter will be returned as a text. For this particular tool, it changes all character to upper case and returns it. If you need help - start here:

    http://help.arcgis.com/en/arcgisdesk...0000006000000/

  7. #7
    William Ide
    Join Date
    Nov 2011
    Posts
    48
    Points
    2
    Answers Provided
    0


    0

    Default Re: Get user input text in arcpy

    I didn't get the zip file.

  8. #8
    Nobbir Ahmed

    Join Date
    Jun 2010
    Posts
    327
    Points
    124
    Answers Provided
    17


    1

    Default Re: Get user input text in arcpy

    Sorry - here it is.
    Attached Files

  9. #9
    William Ide
    Join Date
    Nov 2011
    Posts
    48
    Points
    2
    Answers Provided
    0


    0

    Default Re: Get user input text in arcpy

    Ok I got the Zip file and am working with it.

    I still can't get it to work.

    In the code of calling_script.py (I change to path to where I have it.)

    You have:

    try:
    arcpy.ImportToolbox(r"D:\Myprojects\Arcscripts\POPUP\PopUp.tbx")
    result = arcpy.PopupInputBox_popup("A message from Popupbox")

    the "PopupInputBox_popup" is not resolved and the script won't run. Also the test model has a Red "X" in it and won't run.

    What now.

    This is much harder that using Tkinter.

  10. #10
    Nobbir Ahmed

    Join Date
    Jun 2010
    Posts
    327
    Points
    124
    Answers Provided
    17


    1

    Default Re: Get user input text in arcpy

    Once you get used to it you'll love script tools

    In Catalog tree, right-click on the script tool and select Properties...

    Click on the second tab Source and check whether the path to the script is where you have saved your script:

    Click image for larger version

Name:	pop_up_script_source.png
Views:	157
Size:	7.4 KB
ID:	15181

    If you still get error please email me at nahmed@esri.com - we'll post the result to the thread once solved.

  11. #11
    William Ide
    Join Date
    Nov 2011
    Posts
    48
    Points
    2
    Answers Provided
    0


    0

    Default Re: Get user input text in arcpy

    Nope All I get back is "A Message from popup box" Which is the string going in. Nothing ever pops up. I runs completes ARRRR... I am done with the writing the code in Tkinter. took me about 10 min. I run all the arcpy I need to get the job done. Why isn't Tkinter supported? I think it should be.

  12. #12
    Nobbir Ahmed

    Join Date
    Jun 2010
    Posts
    327
    Points
    124
    Answers Provided
    17


    0

    Default Re: Get user input text in arcpy

    All I get back is "A Message from popup box" Which is the string going in. Nothing ever pops up.
    Nothing will pop up - the tool that you are using is the dialog and substitutes the pop-up. You use it to get a string value from the user. So, in your case, the user will type the name of the report (a string), the script behind the code will capture the string and do whatever you want the script to do. The advantage is that you can chain this dialog (i.e., the tool) in ModelBuilder and any other Python or .Net or Java application. You can drag-drop this tool to an ArcMap toolbar - it will work as a button.

    Why isn't Tkinter supported? I think it should be.
    The reason is TkInter's event loop does not work with ArcMap.

    You can read through these forum threads where some users are able to use TkInter.

    http://forums.arcgis.com/threads/382...hlight=TkInter

    http://forums.arcgis.com/threads/582...hlight=TkInter

    http://forums.arcgis.com/threads/320...hlight=TkInter

  13. #13
    William Ide
    Join Date
    Nov 2011
    Posts
    48
    Points
    2
    Answers Provided
    0


    1

    Default Re: Get user input text in arcpy

    In future releases of Arc 10.x. It seems to me that ESRI could find out where the conflict is with Tkinter and fix it. ESRI seem to be using Python as the main scripting language. Which I think is a good idea. But, if they are, they should adopt it fully and not just the scripting part. That way we developers could bring the whole weight of the Vast python set of tool to bear on any problem we find.

  14. #14
    Jeff Buturff
    Join Date
    Feb 2013
    Posts
    8
    Points
    0
    Answers Provided
    0


    0

    Default Re: Get user input text in arcpy

    I'm stuck on this same concept. Any resolution here?

    All I want to do is be able to provide a text input box to the user. For example, I want the user to "Enter a PIN:". When they do, I search for that pin. Zoom to the selected feature. Buffer it by 100'. Select all the features in the buffer. Create mailing labels of all the features.

    Everything else is easy enough to do with a Python add-in, except Step 1: ASK THE USER FOR INPUT....

  15. #15
    Nobbir Ahmed

    Join Date
    Jun 2010
    Posts
    327
    Points
    124
    Answers Provided
    17


    1

    Default Re: Get user input text in arcpy

    Use a combobox to take the input. Make sure set the combobox's editable property to true.

    Write your code inside the OnEnter event of the combobox.

  16. #16
    Jeff Buturff
    Join Date
    Feb 2013
    Posts
    8
    Points
    0
    Answers Provided
    0


    0

    Default Re: Get user input text in arcpy

    Is there no easy way to present a modal dialog box asking the user for input when they hit a button using a python add-in? This was basic functionality in VBA in ArcGIS 8.0.

    My client has a custom toolbar with 10 buttons on it, each representing a different type of "search". When the user clicks a button, it presents a modal dialog box, asking for the "search item", such as PIN, ADDRESS, POLE_ID, etc.

    My client would prefer this all be written in python for maintenance reasons, but it sounds like Python can't do this simple task...

  17. #17
    Nobbir Ahmed

    Join Date
    Jun 2010
    Posts
    327
    Points
    124
    Answers Provided
    17


    0

    Default Re: Get user input text in arcpy

    Sorry Jeff There is no TextBox add-in even in ArcObjects .Net SDK.

    These controls are created through an IDE. You can use WxPython to create such controls. Here is a blog - check it out:

    Custom wxPython GUI’s: an approach for ArcGIS 10.1

    The easy and safe is to create a script tool (with a string parameter in your case) and call pythonaddins.GPToolDialog(.....) to pop-up that tool.

  18. #18
    Patrick Jurgens
    Join Date
    Apr 2011
    Posts
    17
    Points
    0
    Answers Provided
    1


    0

    Default Re: Get user input text in arcpy

    Quote Originally Posted by NobbirAhmed View Post
    Use a combobox to take the input. Make sure set the combobox's editable property to true.

    Write your code inside the OnEnter event of the combobox.
    The problem with this is that I want to accept a long string from the user, maybe one thousand characters. I can't expect them to enter that in a tiny combo box, and it would be especially lame to make a very large combo box that would use up valuable screen space even when it is not in use.
    A popup window with a text box is what I want. Not a combo box, not a stupid script tool interface.

    The TKinter internal loop back problem has been know about for a long time. Why not fix it already?

    also, wxPython is not a python standard library. At my work place I am unable to install python libraries, so I am stuck with tkinter.
    Last edited by patrick.jurgens; 12-18-2013 at 05:21 AM.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts