Python Add-In: Getting User Input

1709
5
Jump to solution
12-06-2016 11:46 AM
ChrisHolmes
Occasional Contributor III

Hello everyone,

I have been searching and searching and have not been able to find a definitive answer. Is there any way to have a user provide input to a python add-in.  I have a process that runs via a model which uses 2 model parameters (one via a textbox, one via a combobox). I am trying to see if the same process can be done a python add-in.

Thanks,

Chris

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi Chris,

I think the function you want is pythonaddins GPToolDialog(toolbox, tool_name). If you hook that up to a button click event, it will bring up your model's user input form.

Beyond that, you would need to either go the .NET route or leverage a Python-based GUI package like PyQt, tkinter,  or PySide. This is probably overkill for what you're talking about, but if you are interested there's a nice video from an Esri UC on the topic.

Hope that helps! I find pythonaddins to be a lot of fun to work with personally.

Micah

View solution in original post

5 Replies
RebeccaStrauch__GISP
MVP Esteemed Contributor

Does you python add-in use a toolbox/toolbuttons?  Are you using the built in ability with toolbuttons to as for parameters/user-input?  

That is, can the input be done at the start of the program, or are you looking for input while the tool is running, --- more of an interactive input (that I can't help with).

ChrisHolmes
Occasional Contributor III

Hi Rebecca,

The input would be gathered at the start of the program. I have not started working on this yet, just trying to figure out if it's doable.

What I'm looking for is to be able to have something like this appear after selecting the menuitem off of the toolbar where the user would enter the address into the one field and select a LuCode from the dropdown:

Then click "Ok" and the code would run. My hunch is that it's not doable, just hope I'm wrong on that.

Thanks

0 Kudos
by Anonymous User
Not applicable

Hi Chris,

I think the function you want is pythonaddins GPToolDialog(toolbox, tool_name). If you hook that up to a button click event, it will bring up your model's user input form.

Beyond that, you would need to either go the .NET route or leverage a Python-based GUI package like PyQt, tkinter,  or PySide. This is probably overkill for what you're talking about, but if you are interested there's a nice video from an Esri UC on the topic.

Hope that helps! I find pythonaddins to be a lot of fun to work with personally.

Micah

RebeccaStrauch__GISP
MVP Esteemed Contributor

Again, if ok to have at the initial click of the toolbutton (and not interactive...in which case looks more at Micah's response), you can do most of this with the initial GUI.  For an exmaple, the Server Admin Toolkit

http://www.arcgis.com/home/item.html?id=12dde73e0e784e47818162b4d41ee340 

uses Parameters and the Validate tabs (right click on the tool to modify).

The gui for stopping and starting services looks like

The tool looks for "Server Name", "Port", "Admin User" and "Admin Password" to be entered, then checks that they are valid....then it populates the "Service List" (filters based on the "Stop, Start, Delete" field.

So, if you are setting the parameters at the beginning of running the tool, you have options with the build in features. I would start with a sample like the one above to figure out how to get it to check and populate another box based on input.  There are also probably samples in the help for this.

ChrisHolmes
Occasional Contributor III

Thanks Micah and Rebecca. I will explore the information both of you have provided to me. Very much appreciated!

Chris

0 Kudos