IGraphicsContainer.AddElement error

1631
1
Jump to solution
03-05-2012 08:00 AM
SpencerGardner
New Contributor II
I'm trying to add a new map frame (and accompanying map) to my document's page layout. I'm roughly following the code example from this ESRI example but the process errors out with
Value does not fall within the expected range

Here is the relevant code
            //create the new map with settings             IMap addMap = new Map();             addMap = m_maps.Create();             addMap.Name = scenarioName;             IEnvelope mapExtent = new EnvelopeClass();             mapExtent = (IEnvelope)m_doc.ActiveView.Extent;                          //create new mapframe and set map layout             IMapFrame addMapFrame = new MapFrameClass();             addMapFrame.Map = addMap;             IElement mapFrameElement = (IElement)addMapFrame;             IGraphicsContainer pGC = (IGraphicsContainer)m_doc.PageLayout;             pGC.AddElement(mapFrameElement, 0);

It looks like the AddElement  method doesn't like the integer being passed. I've tried with different int values but still get the same error. What could be causing this error?
0 Kudos
1 Solution

Accepted Solutions
sapnas
by
Occasional Contributor III
I noticed that you are not assigning any value to mapFrameElement.Geometry. I think the error might be associated with unassigned geometry property.  try below statement to fix the issue.
mapFrameElement.Geometry = mapExtent;

View solution in original post

0 Kudos
1 Reply
sapnas
by
Occasional Contributor III
I noticed that you are not assigning any value to mapFrameElement.Geometry. I think the error might be associated with unassigned geometry property.  try below statement to fix the issue.
mapFrameElement.Geometry = mapExtent;
0 Kudos