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

4314
2
02-12-2015 09:02 AM
croemersabris
New Contributor II

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();

        }

    }

}

0 Kudos
2 Replies
croemersabris
New Contributor II

Hi, i wish to recall my question, maybe there is someone who can support in that case.

Regards Christoph

0 Kudos
croemersabris
New Contributor II

Hi,

I didn't solve the problem itself, but i got a workaround:

I realized that the function only ran into nirvana, when the IPageLayoutControl2 was ActiveView before.

If the IMapControl3 was ActiveView the function worked.

So when loading the mxd as template i switched the ActiveView to mapcontrol when it was pagelayoutcontrol before loading and back afterwards.

Regards Christoph

0 Kudos