In a custom ArcMap command implemented in .NET C# I create a new data frame this way:

// mxDocument is IMxDocument
IMap newMap = mxDocument.Maps.Create(); // create new data frame
newMap.Name = "I can name it as I want: " + Guid.NewGuid();
mxDocument.ActiveView = (IActiveView)newMap; // activate new data frame

However, compared to the data frame created with standard ArcMap means, there is something wrong with my data frame:

  1. ArcMap doesn't show property page for the data frame (right click - Properties)
  2. It's not possible to remove my data frame from ArcMap (right click - Remove)

Do I have to add some initialization code for IMap created with IMaps.Create (IMaps2.Create)?

The help for the method is quite laconic: "Creates a new map"...

I use ArcGIS version 10.2.2.


This code snippet should add a new dataframe:

IApplication app = default(IApplication);
IMxDocument pMxDoc = default(IMxDocument);

app = (IApplication)Hook;
pMxDoc = (IMxDocument)My.ArcMap.Application.Document;

//Create a new map
IMap pMap = default(IMap);
pMap = new Map();
pMap.Name = "My Map2";

//Create a new MapFrame and associate map with it
IMapFrame pMapFrame = default(IMapFrame);
pMapFrame = new MapFrame();
pMapFrame.Map = pMap;

//Set the position of the new map frame
IElement pElement = default(IElement);
IEnvelope pEnv = default(IEnvelope);
pElement = pMapFrame;
pEnv = new Envelope();
pEnv.PutCoords(0, 0, 5, 5);
pElement.Geometry = pEnv;

//Add mapframe to the layout
IGraphicsContainer pGraphicsContainer = default(IGraphicsContainer);
pGraphicsContainer = pMxDoc.PageLayout;
pGraphicsContainer.AddElement(pMapFrame, 0);

//Make the newly added map the focus map
IActiveView pActiveView = default(IActiveView);
pActiveView = pMxDoc.ActiveView;
if (pActiveView is IPageLayout) {
    pActiveView.FocusMap = pMap;
} else {
    pMxDoc.ActiveView = pMap;

//Refresh ActiveView and TOC

Sourced from How to create a new map


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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