Select to view content in your preferred language

Capture geoprocessor progress and messages from Pro Net SDK

407
1
Jump to solution
01-24-2023 10:57 PM
LewisTrotter
Occasional Contributor

Hello,

I have a python toolbox that has a tool in it that I want to run from the Pro Net side. Easy to do. However, I was wondering if it is possible to pass the geoprocessors messages and progressor values out of the geoprocessor into Net as the geoprocessor runs. Is this possible?

Basically, I'm trying to create an improved dockpanel UI for the geoprocessor, but I need to do the processing on the python toolbox side.

Thanks!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

You could use the code from Esri community samples:

 

        private async Task<bool> ExecuteDeleteFieldTool(BasicFeatureLayer theLayer, string fieldName)
        {
            try
            {
                return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
                {
                    var inTable = theLayer.Name;
                    var table = theLayer.GetTable();
                    var dataStore = table.GetDatastore();
                    var workspaceNameDef = dataStore.GetConnectionString();
                    var workspaceName = workspaceNameDef.Split('=')[1];

                    var fullSpec = System.IO.Path.Combine(workspaceName, inTable);
                    System.Diagnostics.Debug.WriteLine($@"Delete {fieldName} from {fullSpec}");

                    var parameters = Geoprocessing.MakeValueArray(fullSpec, fieldName);
                    var cts = new CancellationTokenSource();
                    var results = Geoprocessing.ExecuteToolAsync("management.DeleteField", parameters, null, cts.Token,
                        (eventName, o) =>
                        {
                            System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}");
                            if (eventName == "OnMessage")
                            {

                                System.Diagnostics.Debug.WriteLine($@"Msg: {o}");
                            }
                        });
                    return true;

                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
        }

 

 

 

Write specific messages from your python code and you get content of message in event "OnMessage".

Parse message content for specific type.

For example, for progressor message could start with prefix "Progressor:". All message text could look like this "Progressor: 1". It will mean that progressor value must be equal to 1.

 

arcpy.AddMessage("Progressor: 1")

 

P.s. There is "OnProgressMessage" and "OnProgressPos" messages too which you can use directly. Try to investigate in arcpy library.

Solved: How to get return value from python tool - Esri Community

SetProgressor—ArcGIS Pro | Documentation

View solution in original post

1 Reply
GKmieliauskas
Esri Regular Contributor

Hi,

You could use the code from Esri community samples:

 

        private async Task<bool> ExecuteDeleteFieldTool(BasicFeatureLayer theLayer, string fieldName)
        {
            try
            {
                return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
                {
                    var inTable = theLayer.Name;
                    var table = theLayer.GetTable();
                    var dataStore = table.GetDatastore();
                    var workspaceNameDef = dataStore.GetConnectionString();
                    var workspaceName = workspaceNameDef.Split('=')[1];

                    var fullSpec = System.IO.Path.Combine(workspaceName, inTable);
                    System.Diagnostics.Debug.WriteLine($@"Delete {fieldName} from {fullSpec}");

                    var parameters = Geoprocessing.MakeValueArray(fullSpec, fieldName);
                    var cts = new CancellationTokenSource();
                    var results = Geoprocessing.ExecuteToolAsync("management.DeleteField", parameters, null, cts.Token,
                        (eventName, o) =>
                        {
                            System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}");
                            if (eventName == "OnMessage")
                            {

                                System.Diagnostics.Debug.WriteLine($@"Msg: {o}");
                            }
                        });
                    return true;

                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
        }

 

 

 

Write specific messages from your python code and you get content of message in event "OnMessage".

Parse message content for specific type.

For example, for progressor message could start with prefix "Progressor:". All message text could look like this "Progressor: 1". It will mean that progressor value must be equal to 1.

 

arcpy.AddMessage("Progressor: 1")

 

P.s. There is "OnProgressMessage" and "OnProgressPos" messages too which you can use directly. Try to investigate in arcpy library.

Solved: How to get return value from python tool - Esri Community

SetProgressor—ArcGIS Pro | Documentation