Map frame in pagelayout

818
2
04-22-2011 04:49 PM
GagagDa_Morvi
New Contributor
I am doing some custom drawing in the pagelayout view. In that connection, I need to find out the coordinates (or extents) of the map frame that in rendered in the pagelayout view in screen coordinates. Is there a way to find that out?
0 Kudos
2 Replies
AlexanderDorofeev
New Contributor
Loop through elements of pagelayout, if element is MapFrameClass, cast it to IElement, use Geometry property to obtain screen coordinates
0 Kudos
JeffreyHamblin
New Contributor III
I also need to get at this information for a project I'm working on.

Here is my first stab at it as a C# Add-In, just to get the basic concept working. It will likely need some refinement, but this should help anyone else in the same boat get started:
// Get the position and size of the focus map in  the layout.

IActiveView activeView = ArcMap.Document.ActiveView;

// Make sure ArcMap is in layout view
if (!(activeView is IPageLayout))
{
    MessageBox.Show("Please switch to layout view.");
    return;
}

// Look at the page layout as a container and loop through all the elements.
IGraphicsContainer graphicsContainer = activeView as IGraphicsContainer;
graphicsContainer.Reset();
IElement element = null;
while ((element = graphicsContainer.Next()) != null)
{
    // Only work with map frames
    if (element is IMapFrame)
    {
        // Get the map frame's map
        IMap map = (element as IMapFrame).Map;
        // Only work with the focus map frame in layout
        if (map.Equals(ArcMap.Document.FocusMap))
        {
            // Display the map frame's layout position/size
            // which is in reference to lower left corner.
            IGeometry geometry = element.Geometry;
            MessageBox.Show(
                "Left: " + geometry.Envelope.XMin.ToString() +
                "\nTop: " + geometry.Envelope.YMax.ToString() +
                "\nRight: " + geometry.Envelope.XMax.ToString() +
                "\nBottom: " + geometry.Envelope.YMin.ToString());
        }
    }
}


-Jeff H
0 Kudos