Key Ideas
[Part 2 of 12]
The basic code for this part is relatively simple. The main theme is that we need to get hold of the "application" object which represents the running application we are inside. We can then use this to ask for objects inside it.
-
With an addin button we can get the application object
by overriding the
init
method which is passed this object by the system when it initialises the button. It is passed in as anIApplication
implementing object...private IApplication app;
@Override
public void init(IApplication app){
this.app = app;
} -
Once we have this we can use it to get other objects within the application.
In most cases this will involve first getting the open document...
private IApplication app;
@Override
public void init(IApplication app){
this.app = app;
IMxDocument mxDoc = (IMxDocument)app.getDocument();
} - Note that while we don't have to cast to a specific interface in Java (or, indeed, attach the object to an interface-type label), it is worth doing so in Arc, in part because it forces you to think about whether you have the right object, and in part so others coding with ESRI products are clear about your code. For the same reasons, you may consider following the ESRI naming conventions, though these are not altogether helpful if you think people unfamiliar with them will be working with your code.