Arc Addin


The second part of the practical is to get our model running programmatically.


To do this, we need to run it as a tool. The code to do this is in the Cookbook. Look at it carefully - can you see what it is doing?

The code uses a ESRI GeoProcessor to run the tool. The GeoProcessor recognises the names of all the tools added to ArcMap automatically. If you find you need to add a toolbox and tool, the code for that is also in the Cookbook; but we don't need that here.

Have a go at getting the code to run your model. A few hints may help:

1) The order of the parameters is the same as the order in the toolbox version (i.e. top to bottom in the GUI is the same as first, second, third, etc. in the code).

2) Remember that the model label that appears in the toolbox is not the same as the tool name, which you need here. Both can be found in modelbuilder, under the model properties.

3) If you miss out the output as a parameter, Arc will usually write output files to the default GeoDatabase in "My Documents\ArcGIS". However, you may not actually have permission to write to this location, which will cause the model to fail.

4) If you do manage to write to the default geodatabase, the output won't appear in your map. Best to write the output to the same directory as your map. If you are after something more sophisticated, the Cookbook has code to find various user directories.


If you get that working, and have the time and energy for more, have a look at the ESRI java API docs, or have a go at getting the code to run with a progress bar - the code is in the Cookbook.

Note that this process should work just as well with running Python scripts from the Java: Arc just sees these as another tool. Turing perserve me, but you could try saving your model as a script and getting it running in the same manner; I've never tried it, but I'm guessing it should work!