-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArcSWAT3StartButton.cs
82 lines (80 loc) · 4.08 KB
/
ArcSWAT3StartButton.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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.Layouts;
using ArcGIS.Desktop.Mapping;
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using MaxRev.Gdal.Core;
namespace ArcSWAT3
{
internal class ArcSWAT3StartButton : ArcGIS.Desktop.Framework.Contracts.Button
{
protected async override void OnClick()
{
//try
{
// Inform user that add-in is about to call Python script.
// ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Click OK to start script, and wait for completion messagebox.", "Info");
// Create and format path to Project
GdalBase.ConfigureAll();
MaxRev.Gdal.Core.Proj.Configure();
var arcSWATProj = new ArcSWAT();
await arcSWATProj.run();
//var pathProExe = System.IO.Path.GetDirectoryName((new System.Uri(Assembly.GetEntryAssembly().Location)).AbsolutePath);
//if (pathProExe == null) return;
//pathProExe = Uri.UnescapeDataString(pathProExe);
//pathProExe = System.IO.Path.Combine(pathProExe, @"Python\envs\arcswat_env");
// produces ~/AppData/Local/Programs/ArcGIS/Pro/bin/Python/envs/arcswat_env
//Utils.information("pathProExe: " + pathProExe, false);
// Create and format path to Python
// This is where the add-in file ArcSWAT.esriAddinX is stored
//var pathPython = System.IO.Path.GetDirectoryName(new System.Uri(Assembly.GetExecutingAssembly().Location).AbsolutePath);
//if (pathPython == null) return;
//pathPython = Uri.UnescapeDataString(pathPython);
// produces ~/AppData/Local/ESRI/ArcGISPro/AssemblyCache/{...}
//Utils.information(pathPython, false);
//// Create and format process command string.
//// NOTE: Path to Python script is below, "K:\Users\Public\QSWAT3\QSWAT3\runArcSWAT.py", which can be kept or updated based on the location you place it.
//var myCommand = String.Format(@"/c """"{0}"" ""{1}""""",
// System.IO.Path.Combine(pathProExe, "python.exe"),
// System.IO.Path.Combine(pathPython, @"K:\Users\Public\ArcSWAT\runArcSWAT.py"));
//// Create process start info, with instruction settings
//var procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", myCommand);
////procStartInfo.RedirectStandardOutput = true;
////procStartInfo.RedirectStandardError = true;
//procStartInfo.UseShellExecute = false;
//procStartInfo.CreateNoWindow = true;
//// Create process and start it
//System.Diagnostics.Process proc = new System.Diagnostics.Process();
//proc.StartInfo = procStartInfo;
//proc.Start();
//// Create and format result string
////string result = proc.StandardOutput.ReadToEnd();
////string error = proc.StandardError.ReadToEnd();
////if (!string.IsNullOrEmpty(error)) result += String.Format("{0} Error: {1}", result, error);
//// Show result string
////ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(result, "Info");
}
//catch (Exception exc)
//{
// // Catch any exception found and display in a message box
// ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Exception caught while trying to run ArcSWAT: " + exc.Message);
// return;
//}
}
}
}