IMap value is invalid

10-31-2014 03:44 AM
New Contributor

Why ArcMap.Application.Document is null on run? There is my addin. It consist of tool and docWindow. DocWindow opens when tool is selected. When I run ArcMap with selected myTool and opened window, ArcMap.Application.Document is null.

If I call this from DockPanelClass (or other class) :

IMxDocument doc = ArcMap.Application.Document as IMxDocument; IMap map = doc.FocusMap;

map contains 0 layers;

But when I call it from MyToolClass it becomes valid and contains all my map layers. What happens?

0 Kudos
1 Reply
Occasional Contributor III

FocusMap is one of the last things to get populated as a map document is loaded.  At what point is your code being called? 

If your tool is listening to document events you would want to get a reference to the map after IDocumentEvents.OpenDocument and/or IActiveViewEvents.FocusMapChanged have fired.

If you don't need the reference to FocusMap until the tool is being used anyway, there's nothing wrong with calling it from your MyToolClass as you have already done.

0 Kudos