Add-in initialization

2773
1
06-29-2012 07:24 AM
LeoDonahue
Occasional Contributor III
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.

http://help.arcgis.com/en/sdk/10.0/java_ao_adf/conceptualhelp/engine/0001/00010000041v000000.htm

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:

http://help.arcgis.com/en/sdk/10.0/java_ao_adf/api/arcobjects/com/esri/arcgis/addins/desktop/Tool.ht...

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). ?
0 Kudos
1 Reply
AlexanderGray
Occasional Contributor III
Short answer is yes it can slow down ArcMap startup.

if the command is not on the interface when ArcMap starts up then it won't be initialized right away.  For example if the command is on a toolbar that is not visible or a context menu etc.  Then the initialization only starts then.  Just because you can set up objects in the initialization doesn't mean you have to or you should.  I find that sort of thing useful if I want to make a the tool enabled dependent on a license being turned or an extension loaded or an edit session started.  Then the init method would be good.   Otherwise, I instantiate objects when they are needed.
0 Kudos