I am trying to change the scale of a map in an mxd OUTSIDE of ArcMap in a standalone Windows application. The problem is the scale is never persisted - the best code I have come up with is the following:

private void UpdateMapScaleInMxd(double scale, string mxdFullPath)
            IMapDocument mapDocument = new MapDocumentClass();
            mapDocument.Open(mxdFullPath, "");
            IPageLayout pageLayout = (IPageLayout)mapDocument.ActiveView;

            IGraphicsContainer graphicsContainer = (IGraphicsContainer)pageLayout;
            IMapFrame mapFrame;

            IActiveView tmpActiveView = null;

            IElement element = graphicsContainer.Next();
            while (element != null)
                if (element is IMapFrame)
                    mapFrame = (IMapFrame)element;
                    tmpActiveView = (IActiveView)mapFrame.Map;

                    mapFrame.ExtentType = esriExtentTypeEnum.esriExtentScale;
                    mapFrame.MapScale = scale;

                element = graphicsContainer.Next();

            mapDocument.Save(false, false);

I check the mxd by opening it up in ArcMap and the map scale has changed i.e the data frame now has a fixed scale and the scale combobox is greyed out.

So now I try to export the map as a PDF in code - and the most frustrating thing is - it exports the map at the previous scale that was set - NOT the scale I just changed it to! So infuriating - if anyone can help me understand where I am going wrong that would be great.


In the code above I am using the IMapDocument - and I think there are limitations (according to the help):

The IMapDocument interface provides properties and methods for reading map document files (*.mxd, *mxt, .pmf) and writing and saving changes to map document files (.mxd). However, since it is not tied to the ArcMap application, application-specific functionality in the MapDocument will not be persisted. Examples of application specific functionality are toolbar settings, UI customizations, VBA projects, and ArcMap graphs. For desktop developers who need to use this functionality, the MxDocument interface located in the ArcMapUI library is a better choice.

I am now thinking that changing the map scale can not be persisted properly using the IMapDocument interface.

2 Answers 2


Solved - and it took Redlands to come back with a slightly unusual fix, it utilises the InteropServices library - hopefully it will be fixed properly in a future release or patch by ESRI.

public static extern int GetDesktopWindow(); 

private IMapDocument mapDocument = null;

private void ChangeMapScale()
    mapDocument.Open(@"C:\Temp\foo.mxd", null);

    IPageLayout pageLayout = mapDocument.PageLayout;
    IActiveView activeView = (IActiveView)pageLayout;
    IMap map = activeView.FocusMap;

    activeView = (IActiveView)mapDocument.PageLayout;

    map.MapScale = value;

    mapDocument.Save(true, true);

If you manually set the mapframe to fixed-scale and run your code that exports to pdf, do you get the correct results?

If not, perhaps the problem is with the code that does the export. Can you post that code too?

  • Check out my update - do you think this is a right assumption? I doubt there is a difinitive list of the items you can't persist via the IMapDocument interface.
    – Vidar
    Jun 2, 2010 at 15:06

Your Answer

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

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