You have a few options to call AcHydro tools in .NET.For example,1. Using GPDispatch
private static void ArcHydroTool_UsingGPDispatch()
{
try
{
System.Type pSysType = System.Type.GetTypeFromProgID("esriGeoprocessing.GpDispatch.1");
System.Object objDispatch = Activator.CreateInstance(pSysType);
// Set the toolbox
pSysType.InvokeMember(
"Toolbox",
BindingFlags.SetProperty,
null,
objDispatch,
new object[] { @"C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Toolboxes\Arc Hydro Tools.tbx" }
);
// Execute the tool
pSysType.InvokeMember(
"DEMReconditioning",
BindingFlags.InvokeMethod,
null,
objDispatch,
new object[] {
@"cedar_dem",
@"stream",
@"5",
@"10",
@"1000",
@"C:\fzhang\INCIDENTS\INCIDENT_972964\Layers\AgreeDEM16",
"NEGATIVE_NO"
}
);
}
catch (Exception err)
{
//output debug information
System.Diagnostics.Debug.WriteLine(err.Message);
System.Diagnostics.Debug.WriteLine(err.StackTrace);
throw;
}
}
2. Use GPTool
private static void ArcHydroTool_UsingGPTool()
{
try
{
IArcToolboxExtension arcToolboxExt;
IArcToolbox arcToolBox;
IGPTool arcTool;
UID gpUID = new UID();
gpUID.Value = "esriGeoprocessingUI.ArcToolboxExtension";
string gpToolName = "DEMReconditioning";
arcToolboxExt = (IArcToolboxExtension) ArcMap.Application.FindExtensionByCLSID(gpUID);
arcToolBox = arcToolboxExt.ArcToolbox;
arcTool = arcToolBox.GetToolbyNameString(gpToolName);
IArray parameters = arcTool.ParameterInfo;
// Iterate through parameters to get data types
for (int j = 0; j < parameters.Count; j++)
{
IGPParameter gparam = (IGPParameter)parameters.get_Element(j);
Debug.WriteLine("Parameter name: " + gparam.Name);
Debug.WriteLine("Parameter Data Type Display Name: " + gparam.DataType.DisplayName);
Debug.WriteLine("Parameter Data Type Name: " + gparam.DataType.Name);
Debug.WriteLine("Is Parameter required?: " + gparam.ParameterType.ToString());
// Debug.WriteLine("Parameter Value Data Type: " + gparam.Value.DataType.Name);
Debug.WriteLine("Parameter Value as Text: " + gparam.Value.GetAsText());
}
arcTool.Execute(parameters, null, null, null);
}
catch (Exception err)
{
//output debug information
System.Diagnostics.Debug.WriteLine(err.Message);
System.Diagnostics.Debug.WriteLine(err.StackTrace);
throw;
}
}