Add-in initialization

Discussion created by ldonahue on Jun 29, 2012
Latest reply on Jun 29, 2012 by agray1
The Add-in documentation states that the init() method is where you "can" place initialization of objects you are going to use for your mousePressed events of an Add-in Tool.


init() method
When working with one of the ArcGIS Desktop applications it is quite possible that you might need to access various items within the applications. For example, in ArcMap you might wish to access the map (that is, data frame) or layers contained within a map. Your Java application cannot just instantiate an instance of the ArcMap application; instead you are passed a reference to an object that will give you the application that the tool is contained within. The init() method serves this purpose as well as defining any logic that is necessary to initialize your tool (for example: instantiate objects that are needed in your mousePressed() method as one example).

When I place a message dialog in the init() method, it will display the message dialog nearly as soon as ArcMap launches, and before you even choose a mxd to open.

If I instantiate other objects in the init() method of my Add-ins such as forms, utility objects that connect to databases, etc, and this code runs before you even open a map document, assuming you have deployed the Add-in and instantiated all of these objects in the init() method, won't this slow down ArcMap over time during it's startup process?

For example, if all Add-in init() methods are executing even when you launch ArcMap, you're essentially creating a bunch of objects that you might not even use if you're not using any of the Add-ins.

If you look at the API, the Tool init() method states:


Initializes this button with the ArcGIS application it is hosted in.  This method is automatically called by the host ArcGIS application when  the button is initialized. It marks the start of the button's lifecycle.  Clients must not call this method.

"When the button is initialized" == (if the Add-in is deployed, then all Add-in tools, buttons, etc are initialized as soon as ArcMap launches). ?