Code for adding a toolbox and generating a tool within it for use


Details

This code adds a toolbox to the running code, and activates a tool suitable to be run with geoprocessor.execute(). The code needs wrapper stubs generating using the Eclipse ArcGIS Menu -> "Geoprocessing Tool Code Generator"


Original author/s: ESRI
Original location/s: How to consume custom geoprocessing tools in Java applications
Adapted by: Andy Evans
License: unknown


Imports and instance variables

	import com.esri.arcgis.geoprocessing.GeoProcessor;
	import com.esri.arcgis.geoprocessing.gen.ToolGenerator;

Code

	// The following lines are only needed if the toolbox isn't already loaded into ArcToolbox.
	GeoProcessor geoprocessor = new GeoProcessor();
	
	String toolboxName = "Toolbox";
	String toolboxLocation = "C:\\workspaces";
  
	this.geoprocessor.addToolbox(toolboxLocation + "\\" + toolboxName); // Note "\\" escape character.
    
	// Now we generate a working version of the tool. 
	String toolName = "Bomb";
	String wrapperPackageName = null; // You'd change this if you'd set a package name when making the wrapper.
	String metaDataFileDir = null;
	String wrapperOutputLocation = "C:\\workspaces";
            
	ToolGenerator.generateTool(toolName, wrapperPackageName, toolboxName,
					toolboxLocation, metaDataFileDir, wrapperOutputLocation);