Select to view content in your preferred language

Looking for a function which directly executes a python-toolbox and allows other geoprocessing tools to run simultaneously

558
5
08-07-2023 10:18 AM
nadja_swiss_parks
Occasional Contributor II

We developed a python toolbox with one python script. The script doesnot need any parameters set, it just needs to run multiple times. The toolbox is now integrated in an add-in, which works with "Geoprocessing.OpenToolDialog(toolboxPath, null);" and then hitting run. Using this method, we could run the tool and still execute other geoprocessing tools.

Since we dont use any parameters, hitting "Run" is not needed. We found the "ExecuteToolAsync" which runs the tool, but async-style, meaning while this function is running, nothing else can be processed. 

 

 

We need a function, which combines these two: clicking the add-in button will execute the function and it will be executed in a way, so that other geoprocessing tools can run too. Does such a function exist? and if yes, how is it called?

 

 

Here is my Code from the Button.cs, which will be called in the Config.daml:

using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Core.Geoprocessing;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Layouts;
using ArcGIS.Desktop.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO; 

namespace ToolTest
{
internal class Button1 : Button
{
protected async override void OnClick()
{
string installPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string toolboxPath = Path.Combine(installPath, "toolbox.pyt\\Tool");
await Geoprocessing.ExecuteToolAsync(toolboxPath,null,null,null,null, GPExecuteToolFlags.InheritGPOptions);
}
}
}

Tags (2)
0 Kudos
5 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

 You could try the code below (without await):

protected override void OnClick()
{
string installPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string toolboxPath = Path.Combine(installPath, "toolbox.pyt\\Tool");
Geoprocessing.ExecuteToolAsync(toolboxPath,null,null,null,null, GPExecuteToolFlags.InheritGPOptions);
}
0 Kudos
nadja_swiss_parks
Occasional Contributor II

Hi @GKmieliauskas - thank you, unfortunately this didn't work for me. 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

As the last parameter for ExecuteToolAsync call you can try 'GPExecuteToolFlags.GPThread'  

 

0 Kudos
nadja_swiss_parks
Occasional Contributor II

Hi @Wolf  - thank you, unfortunately this didn't work for me. Do you have an other idea?

0 Kudos
nadja_swiss_parks
Occasional Contributor II

Hi @Wolf and @GKmieliauskas 

It still doesnot work as intended. However, the combination of both of your propositions leads to an add-in which at least can open a map in the background. It's not possible to execute a geoprocessing tool while my toolbox is running.

this is the code:

 

protected override void OnClick()
{
string installPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
string toolboxPath = Path.Combine(installPath, "toolbox.pyt\\Tool");
Geoprocessing.ExecuteToolAsync(toolboxPath,null,null,null,null, GPExecuteToolFlags.GPThread);

}

0 Kudos