What ArcObjects are involved in making "Fit to Margins" work for a given Page Layout?

Easier to see from picture below:

enter image description here

  • 1
    You could have a read of resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/… about working with pagelayout elements, which I recommend, or you can go via ICommandItem using the ArcID, I think it's {92D4909E-DF9D-11D1-8779-0000F8751720} esriCore.AlignToMarginsCommand from reference edndoc.esri.com/arcobjectsonline/technicaldocuments/… (Note: very valuable reference, I have it bookmarked); sometimes it is not easy to work out what the command is called internally from the menu string.. – Michael Stimson Oct 24 '18 at 23:30
  • Thanks for your reply Michael. I am going to look a the ICommandItem route, as found a reference to this the other day but still trying to work out the fine grained ArcObjects code (I'm stubborn). Out of interest - do you know what the cyan bordered element is called in ArcObjects? I don't think it's a PageLayout - is it the ActiveView or is it a MapFrame? – Vidar Oct 25 '18 at 10:00
  • 1
    The ActiveView is everything you see in front of you, the map is of type IMapFrame but it also implements other coclasses like IFrameElement, the hook point and size will be implemented in another coclass, perhaps IElement.Geometry resources.arcgis.com/en/help/arcobjects-net/componenthelp/… page layout elements aren't something I've worked with much; I work in the data view almost all of the time but knowing the inheritance tendencies your map frame location and size are most likely implemented in a more general interface. – Michael Stimson Oct 25 '18 at 23:00
  • 1
    I figured it out - and you're right - it's all done on the IElement to alter the LowerLeft point and UpperRight point - this will snap the to the PageLayout. Thank you for help.The Fit to Margins is a bit of a red herring as it's all done by manipulating the IElement. – Vidar Oct 26 '18 at 9:23
  • IIRC the margins are based on IPage.PrintableBounds – Kirk Kuykendall Nov 6 '18 at 16:54

Here is my code that got me the answer - basically it was a case of matching up the coordinates in the 2 corners of UpperRight and LowerLeft:

        IPageLayout pageLayout = mxDocument.PageLayout;
        pageLayout.Page.FormID = esriPageFormID.esriPageFormCUSTOM;
        pageLayout.Page.PutCustomSize(31.75, 15.88);

        IActiveView activeView = pageLayout as IActiveView;
        IEnvelope env = activeView.Extent;

        IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;
        IElement element = graphicsContainer.Next();

        //Enumerate through the graphics container, finding all MapSurroundFrames.
        while (element != null)
            if (element is IFrameElement)
                IPoint lowerLeftPoint = new PointClass();
                lowerLeftPoint.X = 0;
                lowerLeftPoint.Y = 0;
                env.LowerLeft = lowerLeftPoint;

                IPoint upperRightPoint = new PointClass();
                upperRightPoint.X = 31.75;
                upperRightPoint.Y = 15.88;
                env.UpperRight = upperRightPoint;

                element.Geometry = env;
            element = graphicsContainer.Next();

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.