7

I have a a fairly simple script tool dialogue which has been setup to get 6 parameters from the user and return them as the tool output as a list. the aims is that the out put would then be used elsewhere within a python add-in tool. I know I could revert to storing these values as a text file but that's not my preferred option. I can see the result in the results window but just can't get to it.

Below is the script to dialogue calls on closure and the seventh parameter is set to an output to store the first six parameters. I have been using the pythonaddins module to call the tool through PToolDialog(Toolbox,Toolname)

What I really want is to parse the output parameter from the script tool to the Python addin.

Script called by Python tool dialogue:

import arcpy
para1 = arcpy.GetParameter(0)
para2 = arcpy.GetParameter(1)
para3 = arcpy.GetParameter(2)
para4 = arcpy.GetParameter(3)
para5 = arcpy.GetParameter(4)
para6 = arcpy.GetParameter(5)
paraList = [para1,para2,para3,para4,para5,para6]
arcpy.SetParameter(6,paraList)
nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Oct 28, 2013 at 13:16
1
  • 2
    Save yourself some typing with a list comprehension: paraList = [arcpy.GetParameterAsText(i) for i in range(6)] Commented Nov 3, 2013 at 16:18

4 Answers 4

5

Well I couldn't work out how to access the outputs of the script tool from the python addin, but i have achieved the next best thing which works for me. Which was to pass the list from the script in the script tool dialog to a list in the python add in tool. By importing the python add in tool into the script for the script tool I was able to access the list variable.

PythonAddinToolbar.py

 import pythonaddins
 parameterList = []
 pythonaddins.GPToolDialog('Toolbox','PythonDialogTool')

PythonDialogToolScript.py

 import PythonAddinToolbar
 #get parameters from dialog
 para1 = arcpy.GetParameterAsText(0)
 para2 = arcpy.GetParameterAsText(1)
 para3 = arcpy.GetParameterAsText(2)
 para4 = arcpy.GetParameterAsText(3)
 para5 = arcpy.GetParameterAsText(4)
 para6 = arcpy.GetParameterAsText(5)
 paraList = [para1,para2,para3,para4,para5]
 PythonAddinToolbar.parameterList = paraList
answered Oct 30, 2013 at 10:01
0
2

Another option is to exchange parameters by making use of environment variables. However, this works only for strings.

Set an environment variable in the add-in code:

os.environ['TOOLNAME_VAR'] = 'abc'

Read the environment variable in the script tool code:

param = os.environ['TOOLNAME_VAR']
answered Jan 7, 2014 at 14:51
1

The GetParameter returns an object. If you are needing text, I think you would want to use GetParameterAsText which will return a string. Thus, your paraList will be a list of strings. This list can then be parsed and passed to tools/buttons/etc within your addin using python. If I understand your question correctly, this should work for you.

EDIT: I belive SetParameter is useful for passing objects from a script to a script tool. However, I'm not sure this can be passed as a parameter to an addin script. I believe the addin would need to see the parameter values (object or string) a global variable.

answered Oct 28, 2013 at 16:36
3
  • Cheers I have actually written an alternative script which uses GetParametersAsText() and passes these to a string vartiable which is then written to a text file for recall. Commented Oct 29, 2013 at 0:07
  • However what i really want is a way to pass the parameter from the script tool to the python addin which called the script tool. Any ideas?? Commented Oct 29, 2013 at 0:09
  • I would use a global variable. Look here Commented Oct 29, 2013 at 13:32
0

In your script tool, add an output variable for every input that you want to pass on to your add-in script. Make these output variables 'Type' as Derived and match each one with the corresponding input variable (with the 'Obtained from' property). These output variables don't show up in the tool when it is run, but are included in the Result, which can be picked up by the Add-in. You'll have to look into it a bit more as to how to get the ouputs out of the result, but some experimentation should be able to give you your answers.

Hope it helps

EDIT: To get the output from a Result, see this Esri help page,

result = yourscripttool(para1,para2,para3,para4,para5,para6)
output1 = result.getOutput(0) # or result[0]
output2 = result.getOutput(1) # or result[1]

I also found this post, and it looks like the result isn't obtainable from GPToolDialog.

answered Oct 29, 2013 at 13:52
3
  • Thanks but it's trying to access the outputs out of the result that is my problem Commented Oct 30, 2013 at 8:04
  • Hmm... I would think it's fairly straightforward. I've edited my answer, but what add-in are you using and why? Commented Oct 30, 2013 at 13:16
  • Thanks for your added input, hopefully they fix this in the future but for now at least I have a better work around then writing to a text file. Commented Oct 30, 2013 at 15:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.