7

I have created multiple ESRI addins, where the same code is used. I have created a class library, which I can reference rather than duplicating code. I have the following in my ESRI addin code which works fine

IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;

However if the same code is used in the class library, I am unable to build the dll. As the class library does not know about ArcMap,

I have tried

ESRI.ArcGIS.ArcMap.Application arcmapApp = new ESRI.ArcGIS.ArcMap.Application();
IMxDocument mxdoc = arcmapApp.Document as IMxDocument;

However when I run the code in my addin (that references my Class Library), i get the following error

enter image description here

What is the correct way of referencing ArcMap in a class library?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Feb 7, 2017 at 14:22

2 Answers 2

4

I have got this to work, but not using AppRot (one problem is that there could be multiple instances of ArcMap and ArcCatalog), but to just pass the ArcGIS application object from the addin.

Within Addin

public ESRI.ArcGIS.ArcMap.Application arcmap = ArcMap.Application as ESRI.ArcGIS.ArcMap.Application;

Within class library

 public bool isEditing(ESRI.ArcGIS.ArcMap.Application arcMap)
 {
 UID editorUID = new UIDClass();
 editorUID.Value = "esriEditor.Editor";
 IExtension editor = arcMap.FindExtensionByCLSID(editorUID);// (editorUID);// '//as IEditor3;
 IEditor e = editor as IEditor;
 if (e.EditState == esriEditState.esriStateNotEditing)
 {
 return false;
 }
 else
 {
 return true;
 }
 }
answered Feb 13, 2017 at 17:19
3

If you need to create an Application reference then you can create an IMxDocument object which will create a new Application object.

http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriArcMapUI/MxDocument.htm

If you want an existing ArcMap reference you can use AppROT like so:

AppROT appRot = new AppROT();
//appRot.Item[#] gives a reference to all Arc applications currently running
appRot.get_Item(0);
IApplication myApp = appRot.get_Item(0) as IApplication;
IMxDocument mxdoc = myApp.Document as IMxDocument;
answered Feb 7, 2017 at 16:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.