Setting the Custom extent of the Data Frame

2825
2
Jump to solution
05-14-2013 12:56 AM
mdonnelly
Esri Contributor
Hello,

I am wondering if it is possible to set the custom extent of a map document's data frame using ArcObjects 10.1?

I wish to take an existing map document, modify the custom extent of the data frame and then save it. Much the same way as you would do in ArcMap when editing the data frame properties (see image).

[ATTACH=CONFIG]24276[/ATTACH]

Any help would be appreciated.

Regards,

Mark
Regards,
Mark
0 Kudos
1 Solution

Accepted Solutions
mdonnelly
Esri Contributor
Thanks for the feedback.

In the end it was a closely related call I was after:

            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeAdvanced }, new esriLicenseExtensionCode[] { });
            
            //ESRI License Initializer generated code.
            
            String path = args[1];              //Path to map document
            float xMin = float.Parse(args[2]);  //New extent xmin
            float yMin = float.Parse(args[3]);  //New extent ymin
            float xMax = float.Parse(args[4]);  //New extent xmax
            float yMax = float.Parse(args[5]);  //New extent ymax

            IMapDocument mapDoc = new MapDocument();

            if (mapDoc.get_IsMapDocument(path))
            {
                mapDoc.Open(path, null);
                IMap map;
                for (int i = 0; i <= mapDoc.MapCount - 1; i++)
                {
                    map = mapDoc.get_Map(i);
                    IMap currMap = map;
                    IEnvelope env = new EnvelopeClass();
                    IPoint llpoint = new PointClass();
                    llpoint.X = xMin;
                    llpoint.Y = yMin;
                    env.LowerLeft = llpoint;

                    IPoint trpoint = new PointClass();
                    trpoint.X = xMax;
                    trpoint.Y = yMax;
                    env.UpperRight = trpoint;
                    env.LowerLeft = llpoint;
                    env.UpperRight = trpoint;
                    IClone sClone = currMap.SpatialReference as IClone; //Assuming the map document has the correct spatial reference.
                    ISpatialReference newSR = sClone.Clone() as ISpatialReference;
                    env.SpatialReference = newSR;

                    currMap.AreaOfInterest = env;
                }
                mapDoc.Save();
            }
            
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
Regards,
Mark

View solution in original post

0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Mark,

You manipulate the extent throught the IActiveView interface.

Duncan
0 Kudos
mdonnelly
Esri Contributor
Thanks for the feedback.

In the end it was a closely related call I was after:

            m_AOLicenseInitializer.InitializeApplication(new esriLicenseProductCode[] { esriLicenseProductCode.esriLicenseProductCodeAdvanced }, new esriLicenseExtensionCode[] { });
            
            //ESRI License Initializer generated code.
            
            String path = args[1];              //Path to map document
            float xMin = float.Parse(args[2]);  //New extent xmin
            float yMin = float.Parse(args[3]);  //New extent ymin
            float xMax = float.Parse(args[4]);  //New extent xmax
            float yMax = float.Parse(args[5]);  //New extent ymax

            IMapDocument mapDoc = new MapDocument();

            if (mapDoc.get_IsMapDocument(path))
            {
                mapDoc.Open(path, null);
                IMap map;
                for (int i = 0; i <= mapDoc.MapCount - 1; i++)
                {
                    map = mapDoc.get_Map(i);
                    IMap currMap = map;
                    IEnvelope env = new EnvelopeClass();
                    IPoint llpoint = new PointClass();
                    llpoint.X = xMin;
                    llpoint.Y = yMin;
                    env.LowerLeft = llpoint;

                    IPoint trpoint = new PointClass();
                    trpoint.X = xMax;
                    trpoint.Y = yMax;
                    env.UpperRight = trpoint;
                    env.LowerLeft = llpoint;
                    env.UpperRight = trpoint;
                    IClone sClone = currMap.SpatialReference as IClone; //Assuming the map document has the correct spatial reference.
                    ISpatialReference newSR = sClone.Clone() as ISpatialReference;
                    env.SpatialReference = newSR;

                    currMap.AreaOfInterest = env;
                }
                mapDoc.Save();
            }
            
            //Do not make any call to ArcObjects after ShutDownApplication()
            m_AOLicenseInitializer.ShutdownApplication();
        }
Regards,
Mark
0 Kudos