ArcObjects: Programmatic adding of a data frame?

1538
4
Jump to solution
05-17-2019 09:10 PM
TieshengWu
Occasional Contributor

Hi all,

I  used .NET snippet to add a data frame into ArcMap as bellow:

...

Dim pmap As IMap=mxDocument.maps.Create()

pmap.Name="New DataFrame"

mxDocument.Add(pmap)

pmap.AddLayer(pLayer)

mxDocument.UpdateContents()

mxDocument.ActiveView = pmap

mxDocument.ActiveView.Refresh()

...

The newly created data frame 'New DataFrame'  and it's features can be displayed in ArcMap, but it seems not a 'Normal' DataFrame. It can't be double clicked to show property, it doesn't shown in pagelayout and even can't be removed in ArcMap interface..

Maybe what code is missed?

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

This question was asked and answered on this forum 5 years ago here.

ArcMap.Document.PageLayout.ReplaceMaps(pmaps)

View solution in original post

4 Replies
DuncanHornby
MVP Notable Contributor

What exactly is your mxDocument object? The code does not show its declaration so could be anything. The IMxDocument interface has no Add method. You would use IMaps interface to add a new IMap object to the mxd.

TieshengWu
Occasional Contributor

Thanks for your response Hornby. The mxDocument defined as : Dim mxDocument as IMxDocument.

Sorry I mistyped  the 'MxDocument.Maps.Add(pmap)'  as 'MxDocument.Add(pmap)'  above in which MxDocument.Maps is a IMaps object.

Another abnormal is that, in pagelayout view, it's property can be displayd in which it's name is not the 'New DataFrame' but 'Layers' who is the first Data Frame's name. 

0 Kudos
DuncanHornby
MVP Notable Contributor

This question was asked and answered on this forum 5 years ago here.

ArcMap.Document.PageLayout.ReplaceMaps(pmaps)
TieshengWu
Occasional Contributor

Thank you very much Hornby.