MapScale not being persisted properly in mxd when programmatically changed outside of ArcMap environ

Posted by Vidar on Stack Overflow See other posts from Stack Overflow or by Vidar
Published on 2010-06-02T08:13:33Z Indexed on 2010/06/02 8:23 UTC
Read the original article Hit count: 285

Filed under:
|
|
|

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;
            graphicsContainer.Reset();
            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;
                    tmpActiveView.Refresh();
                }

                element = graphicsContainer.Next();
            }

            mapDocument.Save(false, false);
            mapDocument.Close();
        }

I check the mxd by opening it up in ArcMap and the map scale has changed, although the little combobox to change the scale is now greyed out - does anyone know what that means!?

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about arcobjects