Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Better Geoprocessing Tool Error Messages #386

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions pro-sdk/geoprocessing-get-error-messages/Config.daml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<ArcGIS defaultAssembly="geoprocessing-get-error-messages.dll" defaultNamespace="geoprocessing_get_error_messages" xmlns="http://schemas.esri.com/DADF/Registry" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.esri.com/DADF/Registry file:///C:/Program%20Files/ArcGIS/Pro/bin/ArcGIS.Desktop.Framework.xsd">
<AddInInfo id="{1114e724-f744-4e94-81ae-d1a1d8bfd452}" version="1.0" desktopVersion="3.3.52636" product="ArcGISPro">
<Name>geoprocessing_get_error_messages</Name>
<Description>geoprocessing_get_error_messages description</Description>
<Image>Images\AddinDesktop32.png</Image>
<Author>Jonathan Key</Author>
<Company>Esri</Company>
<Date>8/20/2024 10:26:58 AM</Date>
<Subject>Framework</Subject>
<!-- Note subject can be one or more of these topics:
Content, Framework, Editing, Geodatabase, Geometry, Geoprocessing, Layouts, Map Authoring, Map Exploration -->
</AddInInfo>
<modules>
<insertModule id="geoprocessing_get_error_messages_Module" className="Module1" autoLoad="false" caption="Module1">
<!-- uncomment to have the control hosted on a separate tab-->
<tabs>
<!--<tab id="geoprocessing_get_error_messages_Tab1" caption="New Tab">
<group refID="geoprocessing_get_error_messages_Group1"/>
</tab>-->
</tabs>
<groups>
<!-- comment this out if you have no controls on the Addin tab to avoid
an empty group-->
<group id="geoprocessing_get_error_messages_Group1" caption="Get Better GP Tool Error Messages" appearsOnAddInTab="true">
<!-- host controls within groups -->
<button refID="GetGPErrorMessagesButton" size="large" />
</group>
</groups>
<controls>
<!-- add your controls here -->
<button id="GetGPErrorMessagesButton" caption="Get GP Tool Error Message" className="GetGPErrorMessagesButton" loadOnClick="true" smallImage="GenericButtonBlue16" largeImage="GenericButtonBlue32">
<tooltip heading="Tooltip Heading">Tooltip text<disabledText /></tooltip>
</button>
</controls>
</insertModule>
</modules>
</ArcGIS>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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.KnowledgeGraph;
using ArcGIS.Desktop.Layouts;
using ArcGIS.Desktop.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace geoprocessing_get_error_messages
{
internal class GetGPErrorMessagesButton : Button
{
protected override async void OnClick()
{
// Temp parameters to on purposely throw an error.
string in_raster = @"raster";
string out_polygon_features = @"feature";

// Set up the geoprocessing tool's parameter values.
var args = Geoprocessing.MakeValueArray(in_raster, out_polygon_features);

// The geoprocessing tool to run.
string tool_path = "conversion.RasterToPolygon";

System.Threading.CancellationTokenSource _cts = new System.Threading.CancellationTokenSource();

var result2 = await Geoprocessing.ExecuteToolAsync(tool_path, args, null, _cts.Token, callback);
// Exposing the "callback", instead of hiding it behind a lamda expression, for educational purposes.
void callback(string event_name, object o)
{
switch (event_name)
{
// Setup event cases.
case "OnValidate":
// Stops executing if any warnings or error messages.
if ((o as IGPMessage[]).Any(it => it.Type == GPMessageType.Warning))
_cts.Cancel();
// Add specific error message handling to view better information.
if ((o as IGPMessage[]).Any(it => it.Type == GPMessageType.Error))
{
// Get error message. It should be, "ERROR 000865: Input raster: raster does not exist."
string msg3 = (o as IGPMessage[]).ElementAtOrDefault(0).ToString();
// Show message to user.
System.Windows.MessageBox.Show(msg3);
_cts.Cancel();
}
break;
case "OnProgressMessage":
string msg = string.Format("{0}: {1}", new object[] { event_name, (string)o });
System.Windows.MessageBox.Show(msg);
_cts.Cancel();
break;
case "OnProgressPos":
string msg2 = string.Format("{0}: {1} %", new object[] { event_name, (int)o });
System.Windows.MessageBox.Show(msg2);
_cts.Cancel();
break;
}
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions pro-sdk/geoprocessing-get-error-messages/Module1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
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.KnowledgeGraph;
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.Windows.Input;

namespace geoprocessing_get_error_messages
{
internal class Module1 : Module
{
private static Module1 _this = null;

/// <summary>
/// Retrieve the singleton instance to this module here
/// </summary>
public static Module1 Current => _this ??= (Module1)FrameworkApplication.FindModule("geoprocessing_get_error_messages_Module");

#region Overrides
/// <summary>
/// Called by Framework when ArcGIS Pro is closing
/// </summary>
/// <returns>False to prevent Pro from closing, otherwise True</returns>
protected override bool CanUnload()
{
//TODO - add your business logic
//return false to ~cancel~ Application close
return true;
}

#endregion Overrides

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"geoprocessing_get_error_messages": {
"commandName": "Executable",
"executablePath": "C:\\Program Files\\ArcGIS\\Pro\\bin\\ArcGISPro.exe"
}
}
}
43 changes: 43 additions & 0 deletions pro-sdk/geoprocessing-get-error-messages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## Get Better Geoprocessing Tool Error Messages

<!-- TODO: Write a brief abstract explaining this sample -->
This sample demonstrates how to get better Geoprocessing tool error messages by using the event handling built into the Geoprocessing.ExecuteToolAsync() method.

<!-- TODO: Fill this section below with metadata about this sample-->
```
Language: C#
Subject: Framework
Date: 08/20/2024
ArcGIS Pro: 3.3
Visual Studio: 2022
.NET Target Framework: 8.0
```

## Resources

* [API Reference online](https://pro.arcgis.com/en/pro-app/sdk/api-reference)
* <a href="https://pro.arcgis.com/en/pro-app/sdk/" target="_blank">ArcGIS Pro SDK for .NET (pro.arcgis.com)</a>
* [arcgis-pro-sdk-community-samples](https://github.com/Esri/arcgis-pro-sdk-community-samples)
* [ArcGIS Pro DAML ID Reference](https://github.com/Esri/arcgis-pro-sdk/wiki/ArcGIS-Pro-DAML-ID-Reference)
* [FAQ](https://github.com/Esri/arcgis-pro-sdk/wiki/FAQ)

### Sample Data

* No additional data is required.

<!-- TODO: Explain how this sample can be used. To use images in this section, create the image file in your sample project's screenshots folder. Use relative url to link to this image using this syntax: ![My sample Image](FacePage/SampleImage.png) -->
## How to use the sample

1. Open the project in Visual Studio, click the Build menu, and then select Build Solution.
1. Click the Start button to run the project and open ArcGIS Pro.
1. Select the "Start without a template" option in ArcGIS Pro.
1. Click the Add-in tab.
1. Click the "Get GP Tool Error Message" button.
1. The geoprocessing tool will attempt to run, then a pop-up window will appear displaying a more detailed error message.
1. Line 52 catches the thrown error message and the subsequent code passes it to the pop-up window.
1. If the event handler workflow is not used, then the geoprocessing tool will only show an error code and no message.

<!-- End -->
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://esri.github.io/arcgis-pro-sdk/images/ArcGISPro.png" alt="ArcGIS Pro SDK for Microsoft .NET Framework" height = "20" width = "20" align="top" >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
[Home](https://github.com/Esri/arcgis-pro-sdk/wiki) | <a href="https://pro.arcgis.com/en/pro-app/sdk/api-reference" target="_blank">API Reference</a> | [Requirements](https://github.com/Esri/arcgis-pro-sdk/wiki#requirements) | [Download](https://github.com/Esri/arcgis-pro-sdk/wiki#installing-arcgis-pro-sdk-for-net) | <a href="https://github.com/esri/arcgis-pro-sdk-community-samples" target="_blank">Samples</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<NoWarn>CA1416</NoWarn>
</PropertyGroup>
<ItemGroup>
<None Remove="Config.daml" />
</ItemGroup>
<ItemGroup>
<Content Include="Config.daml" />
<Content Include="Images\AddInDesktop16.png" />
<Content Include="Images\AddInDesktop32.png" />
<Content Include="DarkImages\AddInDesktop16.png" />
<Content Include="DarkImages\AddInDesktop32.png" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\launchSettings.json" />
</ItemGroup>
<ItemGroup>
<Reference Include="ArcGIS.Desktop.Framework">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\ArcGIS.Desktop.Framework.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Core">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\ArcGIS.Core.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.Core">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\Extensions\Core\ArcGIS.Desktop.Core.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.Mapping">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\Extensions\Mapping\ArcGIS.Desktop.Mapping.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.Catalog">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\Extensions\Catalog\ArcGIS.Desktop.Catalog.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.Editing">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\Extensions\Editing\ArcGIS.Desktop.Editing.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.Extensions">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\Extensions\DesktopExtensions\ArcGIS.Desktop.Extensions.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.GeoProcessing">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\Extensions\GeoProcessing\ArcGIS.Desktop.GeoProcessing.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.Layouts">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\Extensions\Layout\ArcGIS.Desktop.Layouts.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.KnowledgeGraph">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\Extensions\KnowledgeGraph\ArcGIS.Desktop.KnowledgeGraph.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.Shared.Wpf">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\ArcGIS.Desktop.Shared.Wpf.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.Ribbon.Wpf">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\ArcGIS.Desktop.Ribbon.Wpf.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.DataGrid.Contrib.Wpf">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\ArcGIS.Desktop.DataGrid.Contrib.Wpf.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ArcGIS.Desktop.Resources">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\ArcGIS.Desktop.Resources.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
<Reference Include="ESRI.ArcGIS.ItemIndex">
<HintPath>C:\Program Files\ArcGIS\Pro\bin\ESRI.ArcGIS.ItemIndex.dll</HintPath>
<CopyLocal>False</CopyLocal>
<Private>False</Private>
</Reference>
</ItemGroup>
<Import Project="C:\Program Files\ArcGIS\Pro\bin\Esri.ProApp.SDK.Desktop.targets" Condition="Exists('C:\Program Files\ArcGIS\Pro\bin\Esri.ProApp.SDK.Desktop.targets') AND !Exists('Esri.ArcGISPro.Extensions.targets')" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35201.131
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "geoprocessing-get-error-messages", "geoprocessing-get-error-messages.csproj", "{E2ED2003-3350-4E04-908C-0C4AE7C9778A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E2ED2003-3350-4E04-908C-0C4AE7C9778A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2ED2003-3350-4E04-908C-0C4AE7C9778A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2ED2003-3350-4E04-908C-0C4AE7C9778A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2ED2003-3350-4E04-908C-0C4AE7C9778A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D90B5070-76C9-43E3-AFB9-91E1E478440A}
EndGlobalSection
EndGlobal