AnsweredAssumed Answered

Load/Change Template not working under 10.x ArcGIS Engine .Net c# Application

Question asked by croemer on Feb 12, 2015
Latest reply on Jun 24, 2015 by croemer

Hello,

we have an ArcGIS engine Application .NET in C#.

We have an function to change the layout/template.

Under ArcGIS 9.x it was working fine with mxt-Files.

After migrating to ArcGIS10.2.1 i changed the filter to load also mxd-Files because under 10.x you can only create mxd-"Templates".

 

But our Function is not working anymore.

 

The PageLayout is already drawn from the template but when the mapcontrol from the actual map is loaded into the IPageLayoutControl2 Object by ReplaceMaps, the functions runs into Nirvana and doesn't respond:

    

PageLayout.ReplaceMaps(maps);  

 

Any suggestions? I found nothing in the web.

 

Regards Christoph Römer

 

C# Code:

public override void OnClick()

{

    if (m_hookHelper != null)

    {

         string sFilePath;

        OpenFileDialog dlg = new OpenFileDialog();

        dlg.Filter = "Vorlage (*.mxd)|*.mxd|Vorlage (*.mxt)|*.mxt"

        dlg.Multiselect = false;

        dlg.Title = "Vorlage Öffnen";

        if (dlg.ShowDialog() == DialogResult.OK)

        {

            try

            {

                sFilePath = dlg.FileName;

 

                IMaps maps = new Maps();

                maps.Add(MyMap); //MyMap is IMap

 

                IMapDocument mapDoc = new MapDocumentClass();

                mapDoc.Open(sFilePath, string.Empty);

 

                    //MyLayoutControl is IPageLayoutControl2

                MyLayoutControl.PageLayout = mapDoc.PageLayout;

                MyLayoutControl.PageLayout.ReplaceMaps(maps);                   //!!!       Function doesn't respond, killed after 30 minutes   !!!

 

                IGraphicsContainer pGc = MyLayoutControl.ActiveView.GraphicsContainer;

                IMapSurroundFrame pMapSF;

                IMapSurround pMS;

                pGc.Reset();

                IElement pElem = pGc.Next();

                while (pElem != null)

                {

                    if (pElem is IMapSurroundFrame)

                    {

                        pMapSF = pElem as IMapSurroundFrame;

 

                        if (pMapSF.MapSurround is IMapSurround)

                        {

                            pMS = pMapSF.MapSurround as IMapSurround;

                            if (pMS is ILegend)

                            {

                                pGc.DeleteElement(pElem);

                            }

                        }

                    }

                    pElem = pGc.Next();

                }

                 //refresh

                if (m_hookHelper.ActiveView is IPageLayout)

                {

                    MyLayoutControl.ActiveView.Deactivate();

                    MyLayoutControl.ActiveView.Activate(MyLayoutControl.hWnd);

                    MyLayoutControl.ActiveView.Refresh();

                    MyLayoutControl.Refresh(esriViewDrawPhase.esriViewForeground, null, null);

                }

            }

            catch (Exception)

            {               

                    MessageBox.Show("Die Vorlage konnte nicht geladen werden.","Vorlage Laden");

            }

        }

        if (m_hookHelper.ActiveView is IMap)

        {

            MyMapControl.ActiveView.Refresh();

        }

    }

}

Outcomes