How to show progress in .NET application that calls out to python script?

801
4
10-25-2017 10:36 AM
MKF62
by
Occasional Contributor III

I have a python script that does a lot of things with cursors and such. I have done a lot of arcpy.AddMessage throught the script to have it run in ArcMap with progress messages. Now, I am implementing this script in a .NET web application (MVC). I call it (using C#) like so:

IGeoProcessor2 gp = new GeoProcessorClass();
gp.AddToolbox(@"C:\Users\mfxxx10\Desktop\GIS_Testing\HbtatTesting\HabitatMon.tbx");
IVariantArray parameters = new VarArrayClass();
parameters.Add(shapefile);
gp.Execute("PopulatePatches", parameters, null);‍‍‍‍‍‍‍‍‍‍

Now, in my view, I have a button that you press to upload your file and run this script. When that button is pressed, I'd like to have something pop up indicating progress of the script running. What would be really awesome would be to get the progress messages (like those I have encoded with arcpy.AddMessage) to show up also, though this isn't entirely necessary.

Is there any way to do this since I'm calling out to a python script rather than doing all the processing within the C# scripting?

Tags (1)
0 Kudos
4 Replies
YuanLiu
Occasional Contributor

The Geoprocessing Events Listener sample should be of interest to you arcobjects-sdk-community-samples/Net/Geoprocessing/GPEvents at master · Esri/arcobjects-sdk-communit... 

MKF62
by
Occasional Contributor III

Sadly, the sample data download link is broken so it's not particularly helpful, but you've given me something to start googling so thanks!

Edit: Anybody looking for the sample data, I found it here: Geoprocessing events listener 

0 Kudos
DuncanHornby
MVP Notable Contributor

So your ArcObjects code is calling an existing python script which is a script tool in a toolbox? You are not planning to port your python code into ArcObjects, simply call an existing script. This is what I understand you are asking? You would like to hook into the messages that are displayed if this tool was say run from ArcToolbox in ArcMap?

Well below is some VBA code that shows you how to call a standard tool from within ArcObjects code and actually show it's user interface, rather than executing the tool behind the scenes. This open up the dialog window for me so I could see all the scripting messages. This is one way to go?

Public Sub OpenCalculateTool()
    ' Hook into Toolbox and get the tool
    Dim pUID As New UID
    pUID = "esriGeoprocessingUI.ArcToolboxExtension"
    Dim pArcToolboxExtension As IArcToolboxExtension
    Set pArcToolboxExtension = Application.FindExtensionByCLSID(pUID)
    Dim pArcToolbox As IArcToolbox
    Set pArcToolbox = pArcToolboxExtension.ArcToolbox
    Dim pGPTool As IGPTool
    Set pGPTool = pArcToolbox.GetToolbyNameString("CalculateField")
 
    ' Create messages, required by Invoke method
    Dim msgs As IGPMessages
    Set msgs = New GPMessages
 
    ' Get existing parameter structure
    Dim pArray As IArray
    Set pArray = pGPTool.ParameterInfo
 
    ' Declare Parameter interfaces
    Dim pGPParameter As IGPParameter
    Dim pGPDataType As IGPDataType
    Dim pGPParameterEdit As IGPParameterEdit
 
    ' Set the parameters of the tool
    Set pGPParameter = pArray.Element(0)
    Set pGPParameterEdit = pGPParameter
    Set pGPDataType = pGPParameter.DataType
    Set pGPParameterEdit.Value = pGPDataType.CreateValue("a") ' Featurelayer name
    Set pGPParameter = pArray.Element(1)
    Set pGPParameterEdit = pGPParameter
    Set pGPDataType = pGPParameter.DataType
    Set pGPParameterEdit.Value = pGPDataType.CreateValue("xx") ' Field
    Set pGPParameter = pArray.Element(3)
    Set pGPParameterEdit = pGPParameter
    Set pGPDataType = pGPParameter.DataType
    Set pGPParameterEdit.Value = pGPDataType.CreateValue("VB")
 
    ' Open the tool
    Dim pGPToolCommandHelper As IGPToolCommandHelper2
    Set pGPToolCommandHelper = New GPToolCommandHelper
    pGPToolCommandHelper.SetTool pGPTool
    pGPToolCommandHelper.InvokeModal 0, pArray, True, msgs
End Sub
0 Kudos
WilliamKuykendall
New Contributor

I'd take a look at the IGeoProcessor2.RegisterGeoProcessorEvents3 Method

And provide it a class that implements IGeoProcessor3.

Problems have been reported, however, but maybe they've been fixed.

https://community.esri.com/thread/91282 

0 Kudos