Issue with trying to use Geoprocessing.ExecuteToolAsync-method in add-in for ArcGIS Pro 2.9

103
0
03-08-2022 07:11 AM
Labels (1)
PhilipBaggerBenteBent
New Contributor

Hi,

I am attempting to call a Python-tool that I made, from within an add-in for ArcGIS Pro 2.9.1 using the following .NET code:

internal class LoadInfrastructureData : Button

{

  protected override void OnClick()

  {

    string toolPath = "trafficanalyst.InfrastructureConnectivityTool";

 

    string linklayerPath = "C:\\Temp\\NaestvedDemoModelND.gdb\\TA\\Link";

    string networkDatasetPath = "C:\\Temp\\NaestvedDemoModelND.gdb\\TA\\TA_ND";

    string linkConnectivityPath = "C:\\Temp\\LinkConnectivity.csv";

    string pointCandidatesPath = "C:\\Temp\\PointCandidates.csv";

    string stopLayerPath = "C:\\Temp\\NaestvedDemoModelND.gdb\\TA\\Stop";

    string viaPointsPath = "#";

    string stopLayerWhereClause = "#";

    string linkLayerWhereClause = "#";

    string initialSearchDistance = "50";

    string maxSearchDistance = "150";

    string maxSnapDistance = "0.1";

 

    string[] args = {

    linklayerPath,

    networkDatasetPath,

    linkConnectivityPath,

    pointCandidatesPath,

    stopLayerPath,

    viaPointsPath,

    stopLayerWhereClause,

    linkLayerWhereClause,

    initialSearchDistance,

    maxSearchDistance,

    maxSnapDistance

    };

 

    var loadInfrastructureTask = QueuedTask.Run(async () =>

    {

        IGPResult result = await Geoprocessing.ExecuteToolAsync(toolPath, args, flags:GPExecuteToolFlags.None);

    });

}

 

I have tried using the following as toolpath when calling Geoprocessing.ExecuteToolAsync(toolPath, args):

  • Full path to my tool - @"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\TrafficAnalyst\esri\toolboxes\Traffic Analyst Tools.pyt\InfrastructureConnectivityTool"
  • toolboxalias.toolname – ”trafficanalyst.InfrastructureConnectivityTool”
  • toolname_toolboxalias – ” InfrastructureConnectivityTool_trafficanalyst”
  • gp.toolboxalias.toolname – ”gp.trafficanalyst.InfrastructureConnectivityTool”

Common to all four ways of specifying the toolPath parameter, is that I get the value 2147483647 as the ErrorCode from the returned IGPResult as shown below:

PhilipBaggerBenteBent_0-1646752015006.png

 

If I replace toolPath and args with a standard Esri tool, it works fine.

If I run my Python-tool from within ArcGIS Pro GeoProcessing, it works fine.

If I run my Python-tool via an ArcGIS Pro Python prompt, it works fine.

 

What am I doing wrong?

0 Kudos
0 Replies