Saturday, 21 April 2018

arcpy - Accessing the output of a Python script tool dialog ArcGIS 10.1


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)

Answer



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

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...