Hopefully you've managed to get the first practical up and running. If not, grab us and we'll go through it with you. Having done that, we're now going to start the proper programming. We're going to develop an ArcMap addin, and get it to run our model programmatically.
Why? You may well ask. Well, let us imagine, for the sake of argument, that the explosion point was not stored in a passive point file, but was a constantly updated feed, the potential explosion point being sent to us from a monitoring system. Or we might want to allow our users to pick from only certain buffer radii. Or, perhaps, we want to make this part of a bigger system that takes results from a model external to Arc. In short, there are lots of reasons, but many of them come down to having code produce the inputs then fed to the model, or directing the outputs into some code.
This practical will be built up in two stages. In the first, we'll just develop a "Hello World" example. In the second, we'll alter this example to run our pre-practical model.
First up, we'll need to get up and running with Eclipse and the ESRI plugin. Although there is a copy of Eclipse installed on the Uni system, we're not going to use it. It looks like the system settings don't let you install plugins. It's not clear if that's on purpose, or accidental, but either way it's not going to stop us - we're not users, we're coders! We are CHAOS! So, first things first, download a copy of 64 bit Eclipse (note that if you are running Arc 10.3 or below, you may need the 32 bit version -- you'll know if you can't find the AddIns within the customisation interface). You should be able to install Eclipse without Admin rights. Pick the version "for Java Developers" during the install, and install it into m:\eclipse - don't run it just yet. Note first that because it will run off your m: drive, it will ask you when you start it for a workspace. Give it the directory m:\java\eclipse (you can give it something else if you want, but a) don't give it the m:\eclipse directory, and b) we'll assume throughout that you're using m:\java\eclipse). Note also, on the same dialog you can (and should) specify not to be asked for this again. Right, now start it up. If there's no menu item, double click eclipse.exe in the install directory from Windows Explorer or equivalent.
Now you'll need to install the ESRI plugin for Eclipse, the IDE we'll use during this course. You can find details of how to do this on the Help with Software page.
Next, work through the lecture notes on making a addin button (read through the following notes first, down to the next dashed line...).
- MOST IMPORTANT: on the project wizard first page, make sure the JRE version is set to 1.8, which is what Arc 10.4 seems to work with (for Arc 10.2 and below you may find you need 1.6).
- Call the project ModelRunner or something similar.
- You may also need to change the default file saving location from "m:\java\eclipse" to wherever you want to store your files, but we'd recommend that directory -- Eclipse will make a subdirectory for each project.
- Note that the list on the left of the form displays captions, not names. When you give the Button a caption, the list on the left of the may not update the caption - just click it to make it update.
- When you make the class, use the package
- When you make a new addin project you may need to close the "Welcome" screen to see the project.
Get to the point in the lecture notes where
you have a
onClick method, and add a
JOptionPane inside it to popup
a message dialog with "Hello World" on it. If you copy in the
JOptionPane code from the
slides, you'll find that they get underlined in red. This indicates a problem with the code. If you
'mouse-over' the line, you should get a pop-up label that gives you an analysis and various solutions.
In this case you probably haven't imported
javax.swing. If you click this option on the
pop-up, it will do it for you, and the red will disappear. Neat hu?
NB: Static calls to
JOptionPanes are really useful for this kind of stuff, and
there are lots of different dialogs. It is worth checking out their docs:
Export the addin, and build it into ArcMap: use the map you saved for the practical one, and
make sure the toolbox with your model in it is still there. You'll need to look at the slides for
installing an addin in order to do this. The best place to export to is
Run the addin, as per the lecture notes.
If you have trouble, give us a shout.
Once you've got that running, visit the Course Code Cookbook. I know, I know, don't get excited - it will become a cornucopia of delights as we go on. For now, find the "HelloWorld for the ArcMap status line" and give that a go. Note that it has two methods and an instance variable that need setting up. This code uses the application object to get hold of the Arc statusbar - this is the bar at the bottom of the screen. The application is the gateway to everything in Arc, and this is just a simple example of how to use it. You'll need to sort out a variety of red-underlined import and variable creation issues.
Once you've tried all that, either cull out the "Hello World" code from what you've got, or make yourself a new button. In Part Two we're going to use this to run our model.