I am currently in the process of creating Addin's and also converting our VBA projects to .NET addins. With the VBA applications, they would only work with specific MXD's. Is this possible to do with Addin's as well?
2 Answers
You can write your add-in to only respond to events when a specific document is open. CoCreate an MxDocument
in ArcMap, cast to IMapDocument
and check the DocumentFilename
property to see if it's a map document you plan on supporting. It's extra code, but it works.
-
As has been implied in the comments and this answer by Jason you really have no other option here aside from checking the name of the .MXD and validating it against some value. The downside to this is that if the user changes the name of the .MXD for whatever reason it will no longer work. There is unfortunately no unique identifier of a .MXD file independent of the file name that is exposed through ArcObjects.– ConorDec 2, 2013 at 17:45
You can always implement an application extension and persist any data in the MXD, including some kind of flag which would signify that other parts of your addin should be available for that particular document.
IDocumentInfo.Keywords
. I think you could probably also implement persistence on the MXD if you needed more structured storage, but I've never had to do it for an AddIn.