<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic pythonaddins.GPToolDialog in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pythonaddins-gptooldialog/m-p/521972#M40923</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am having problems with retrieving and using user input in phthonaddins. The only tool available that I know of is the GPToolDialog function (if there is an alternative, please let me know). I have tried using it several ways, but none work satisfactorily. The 1st way is a two button approach, in which the function is used in one button, and the rest of the code is run in a second button. This works, but is cumbersome. I have tried a one button approach several ways. When I invoke the GPToolDialog in my primary add-in code, I see the Parameters Dialog for the 2nd tool, but no further code in the primary .pyt will run after the parameters are set. I can add code in the 2nd tool, and it will run, but, strangely, only if I click the screen while the "Executing GetParameters (the 2nd tool)" window is running. How do I retrieve and use the parameters set by the user?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank You,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Aulton Smith&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Jul 2013 14:44:06 GMT</pubDate>
    <dc:creator>AultonSmith1</dc:creator>
    <dc:date>2013-07-22T14:44:06Z</dc:date>
    <item>
      <title>pythonaddins.GPToolDialog</title>
      <link>https://community.esri.com/t5/python-questions/pythonaddins-gptooldialog/m-p/521972#M40923</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am having problems with retrieving and using user input in phthonaddins. The only tool available that I know of is the GPToolDialog function (if there is an alternative, please let me know). I have tried using it several ways, but none work satisfactorily. The 1st way is a two button approach, in which the function is used in one button, and the rest of the code is run in a second button. This works, but is cumbersome. I have tried a one button approach several ways. When I invoke the GPToolDialog in my primary add-in code, I see the Parameters Dialog for the 2nd tool, but no further code in the primary .pyt will run after the parameters are set. I can add code in the 2nd tool, and it will run, but, strangely, only if I click the screen while the "Executing GetParameters (the 2nd tool)" window is running. How do I retrieve and use the parameters set by the user?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank You,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Aulton Smith&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Jul 2013 14:44:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pythonaddins-gptooldialog/m-p/521972#M40923</guid>
      <dc:creator>AultonSmith1</dc:creator>
      <dc:date>2013-07-22T14:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: pythonaddins.GPToolDialog</title>
      <link>https://community.esri.com/t5/python-questions/pythonaddins-gptooldialog/m-p/521973#M40924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here are some things I've done:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Scenario 1:&lt;/STRONG&gt;&lt;SPAN&gt; You need to use outputs immediately, i.e.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;class Button(object):
 def onClick(self):
&amp;nbsp; result = PromptUser("Enter information")
&amp;nbsp; # do something with the result&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When this use case can't be solved using the pythonaddins module, one solution is to launch a custom Tkinter dialog in a subprocess and then pipe in the results.&amp;nbsp; This works best if you don't have a lot of data to pass, although you can read and write from a temporary file to pass more data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;cf. &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/65186-Python-Add-In-User-Input" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/65186-Python-Add-In-User-Input&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Scenario 2:&lt;/STRONG&gt;&lt;SPAN&gt; You don't need to use the outputs immediately, i.e.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;result = None

class Button1(object):
 def onClick(self):
&amp;nbsp; global result
&amp;nbsp; result = PromptUser("Enter information")

class Button2(object):
 def onClick(self):
&amp;nbsp; global result
&amp;nbsp; if result is not None
&amp;nbsp;&amp;nbsp; # do something with the result
&amp;nbsp;&amp;nbsp; result = None&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One way to solve this is just to apply Scenario 1 and then output the results to a global variable.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another way to solve this is to launch a Python tool and read and write your inputs and outputs from temporary files.&amp;nbsp; This makes the most sense when you need the user to execute a tool, but want to control the tool inputs and outputs.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To do this, within Button1.onClick(), you would write any inputs you need for the tool (i.e. the results of previous user interaction in your add-in) to a temporary file and then launch the tool from a toolbox you've included in your add-in's \Install directory.&amp;nbsp; This toolbox is not otherwise exposed to the user.&amp;nbsp; Next, in the __init__ for the tool, read the temporary file to retrieve the inputs.&amp;nbsp; It's guaranteed to be there since you just wrote it prior to launching the tool.&amp;nbsp; In the execution() of the tool, after using the temporary file inputs and the tool parameter inputs to do your processing, write your outputs to a secondary temporary file.&amp;nbsp; Finally, in Button2.onClick(), check whether this output temporary file exists.&amp;nbsp; When it does, read it in, delete it, and then do whatever needs to be done with its data.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can use pickling to easily pass variables back and forth.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;---&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;GPToolDialog launches the tool asynchronously.&amp;nbsp; It's just designed as a shortcut to pop open a tool dialog, which is why I think you're having problems.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:46:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pythonaddins-gptooldialog/m-p/521973#M40924</guid>
      <dc:creator>AdamWehmann</dc:creator>
      <dc:date>2021-12-11T22:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: pythonaddins.GPToolDialog</title>
      <link>https://community.esri.com/t5/python-questions/pythonaddins-gptooldialog/m-p/521974#M40925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it possible to pass arguments to a GP tool using&amp;nbsp; pythonaddins.GPToolDialog?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I.e. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Arg1 = 'The path of a shapefile'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Arg2 = 'Some other value obtained before invoking the tool'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;start = pythonaddins.GPToolDialog("G:\\FIS_Tools\\FIS_Tools.tbx", 'GIStoGPX', 'Arg1', 'Arg2')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I just want to use the pythonaddins.GetSelectedTOCLayerOrDataFrame() to populate the input shapefile by default.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 00:07:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pythonaddins-gptooldialog/m-p/521974#M40925</guid>
      <dc:creator>TimBarnes</dc:creator>
      <dc:date>2013-07-24T00:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: pythonaddins.GPToolDialog</title>
      <link>https://community.esri.com/t5/python-questions/pythonaddins-gptooldialog/m-p/521975#M40926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not as far as I know, but that should definitely be an update to GPToolDialog() in the future.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jul 2013 02:21:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pythonaddins-gptooldialog/m-p/521975#M40926</guid>
      <dc:creator>AdamWehmann</dc:creator>
      <dc:date>2013-07-24T02:21:51Z</dc:date>
    </item>
  </channel>
</rss>

