I've been experimenting with the Military Aspects of Terrain Template, which has a toolbox associated with it. I've been using the following WPF Runtime code, which should open a tool in the associated toolbox . . .
private void RunToolButton_Click(object sender, RoutedEventArgs e)
{
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
//Set a reference to the IGPCommandHelper interface.
IGPToolCommandHelper pToolHelper = new GPToolCommandHelperClass() as IGPToolCommandHelper;
//Set the tool you want to invoke.
string toolboxName = @"C:\ArcGISForDefense\Intelligence\MilitaryAspectsOfTerrainTemplate\Maps\Toolbox\Military Aspects of Terrain Toolbox.tbx";
pToolHelper.SetToolByName(toolboxName, "CoverFromFlatTrajectoryWeapons");
// Generate the array of parameters.
IArray parameters = new ArrayClass();
parameters.Add(@"C:\ArcGISForDefense\Intelligence\MilitaryAspectsOfTerrainTemplate\Maps\OperationGDB.gdb\BrigadeAOI");
parameters.Add(@"C:\ArcGISForDefense\Intelligence\Operational_Environment\Data\MAoT\MAoT.gdb\CombinedVegetationCoverage");
parameters.Add(@"C:\ArcGISForDefense\Intelligence\MilitaryAspectsOfTerrainTemplate\Maps\OperationGDB.gdb\CoverAreas");
//Invoke the tool.
pToolHelper.Invoke(parameters);
}
When I try to run the code, I get the following error message, then it crashes at the "invoke" method . . . "Failed to open tool CoverFromFlatTrajectoryWeapons (Military Aspects of Terrain Toolbox.tbx)" Am I using the right syntax for opening a tool that is in the "Cover and Concealment" toolset, which is in the "Military Aspects of Terrain Toolbox.tbx" toolbox? Am I doing anything wrong that would prompt this error message? I would appreciate any help.
I also wrote the following routine as an alternative, but this also bombs when it gets to the last line of the routine . . .
public void Run_CoverFromFlatTrajectoryWeapons_Tool()
{
// Initialize the geoprocessor.
//Insert this line before invoking any ArcObjects to bind Engine runtime.
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);
GeoProcessor gp = new GeoProcessor();
// Add the toolbox.
gp.AddToolbox(@"C:\ArcGISForDefense\Intelligence\MilitaryAspectsOfTerrainTemplate\Maps\Toolbox\Military Aspects of Terrain Toolbox.tbx");
// Generate the array of parameters.
IVariantArray parameters = new VarArrayClass();
parameters.Add(@"C:\ArcGISForDefense\Intelligence\MilitaryAspectsOfTerrainTemplate\Maps\OperationGDB.gdb\BrigadeAOI");
parameters.Add(@"C:\ArcGISForDefense\Intelligence\Operational_Environment\Data\MAoT\MAoT.gdb\CombinedVegetationCoverage");
parameters.Add(@"C:\ArcGISForDefense\Intelligence\MilitaryAspectsOfTerrainTemplate\Maps\OperationGDB.gdb\CoverAreas");
// Execute the model tool by name.
gp.Execute("CoverFromFlatTrajectoryWeapons", parameters, null);
}
By the way, the above mentioned tool does run well with the specified parameters when running it in ArcMap.
Thanks, Renee
No comments:
Post a Comment