Wednesday, 30 November 2016

arcobjects - Getting ArcMap reference without launching application?


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;

pApp.OpenDocument(MXDPath);

MessageBox.Show("Doc opened");

Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...