Monday, 7 May 2018

arcpy - How to access output parameters from a Python Toolbox Tool called by .NET?


I am trying to access an output parameter from a Python toolbox tool and cannot find any information about how this is done:



I am developing an Esri Add-In for ArcGIS 10.1 SP1 for Desktop (Build 3143) and programming against ArcObjects SDK for the Microsoft .NET Framework 10.1 SP1 using C#.


I am calling a Python Toolbox tool using the following code:


// Call scripting tool from toolbox and show GUI
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string toolbox = Path.Combine(Path.Combine(assemblyFolder, "Toolbox"), @"Amec Foster Wheeler Groundwater Tools.pyt");
string toolname = "CreateBlankGroundwaterGeodatabase";
// Open Dialog for entering parameters
IGPToolCommandHelper2 toolHelper = new GPToolCommandHelperClass() as IGPToolCommandHelper2;
toolHelper.SetToolByName(toolbox, toolname);
IGPUtilities gpUtils = new GPUtilities();

IGPTool tool = toolHelper.Tool;
IArray parameters = tool.ParameterInfo;
IGPMessages gpMessages = new GPMessagesClass();
bool pok;
toolHelper.InvokeModal(0, parameters, out pok, out gpMessages);

// What needs to be done here to get the values of the parameters, the user entered during the execution?
// How can I retrieve output parameter values here?

This is working as expected. The tool dialog opens up in ArcMap and the tool is running without any errors.



In the Python tool itself I am defining one parameter as output parameter


def getParameterInfo(self):
# [..]
param5 = arcpy.Parameter(
displayName="out_fcpath",
name="out_fcpath",
datatype="GPString",
parameterType="Derived",
direction="Output"
)


params = [param0, param1, param2, param3, param4, param5]
return params

And in the execute function I am setting this parameter to a string value.


def execute(self, parameters, messages):
# [..]
arcpy.SetParameterAsText(5,"Test")

return


But how can I retrieve that parameter by code in C# after the tool has been executed? Perhaps you can point me into the right direction?


References:



  1. Get results from programmatically-launched geoprocessing tool

  2. Running a geoprocessing tool using background geoprocessing with custom tool




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...