Adding mapgrid to existing mapinsets in ArcObjects .Net (C#)

26
0
2 weeks ago
Highlighted
New Contributor

am facing the problem to add a mapgrid to existing map insets created in a pagelayout at an earlier step. I can implement some code in a DLL loaded by reflection to add some operations like adding a north arrow, a legend or modifying existing elements of the pagelayout using an available interface. Up to now I am able to get the created map insets and to create the map grid but I have difficulties to "link" them together.

Here is the code I tried:

   for (int i = 0; i < localMap.MapSurroundCount; i++)
   {
               IMapSurround mapSurround = localMap.MapSurround[i];
                if (mapSurround is MapInset)
                {
                    IMapInset mapinset = mapSurround as IMapInset;
                    IFrameElement frameElement = graphicsContainer.FindFrame(mapinset);
                    if (frameElement != null)
                    {
                        ICustomOverlayGrid mapGridCarroyage = new CustomOverlayGridClass();
                        ... 
                        ... setting some properties for  mapGridCarroyage
                        ...
                        IMapFrame mapFrame = frameElement as IMapFrame;
                        IMapGrids mapGrid = mapframe as IMapGrids;
                        mapGrid.AddMapGrid(mapGridCarroyage);
                    }
               }
         
         }

mapFrame is always null but localMap.Mapssurround[i] is returning correctly an existing MapInset and frameElement is not null.

What is going on? what am i doing wrong?

Tags (2)
Reply
0 Kudos
0 Replies