Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to get hold of ArcMap properties in order to change the data source of the layers within it.

I have developed a similar utility earlier utilizing ICommand, but I was curious if I could get a reference to ArcMap application outside of it and change the layer sources and display the new map.

I am using the following code but it instantly launches ArcMap and after that I have no hold on the application i.e. if I terminate my application, ArcMap is still running in background.

Is it possible to get a silent, invisible reference to ArcMap?

IApplication pApp;
IDocument pDoc;
IMxDocument pMxDoc;
string MXDPath = "C:\\NORMALTEMPLATE\\OLD_Normal.mxd";

pDoc = new MxDocumentClass(); //ArcMap launches here
pApp = pDoc.Parent;

MessageBox.Show("Doc opened");
share|improve this question
up vote 4 down vote accepted

You CAN access a running instance of ArcMap (including starting and closing that instance), but the best thing in your scenario is to use the MapDocument class. It is specifically designed for purposes of working with a map document without the need to start an ArcMap instance.

share|improve this answer
Right. Creating an instance of MxDocument creates an instance of MxApplication (ArcMap). – Jim B Jun 1 '11 at 15:05
Great..Thanks! :) – ujjwalesri Jun 2 '11 at 4:32
OK, the happiness was rather short lived :( MapDocument.MapCount makes the application crash for a MXT which has data source missing... – ujjwalesri Jun 2 '11 at 11:32
@ujjwalesri: I tried that specific case and had no problems. Are you properly checking out the licence? – Petr Krebs Jun 2 '11 at 13:11
@Petr: I forgot to check out the license. Did that, program moved further..but failed again at the same point...any ideas? I am getting this error: " could not be found. (Exception from HRESULT: 0x80030002 (STG_E_FILENOTFOUND))" – ujjwalesri Jun 3 '11 at 7:25

I haven't look into this carefully, but the arcpy mapping module seems promising assuming that you aren't adverse to working in Python.

share|improve this answer
This looks good, but I don't have any working experience with Python. I am currently developing in Dot Net. But Thanks for the answer! :) – ujjwalesri Jun 1 '11 at 12:40
The mapping module is pretty sweet, all things considered. It's a great start to map layout manipulation in python. I can only hope ESRI continues to make more parts of the UI (and its various functions) available outside of arcobjects. – Nathanus Jun 1 '11 at 14:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.