Create a Dataframe in Arcpy

4963
5
12-09-2015 06:47 AM
StephanieLassieur
New Contributor

Hi,

I am writing a script which is loading data in various data frames, therefore I need to create Data Frame using python.

I understood there is no straight forward method to do so in Arcpy like addLayer .

However I found this VB dll that is doing a copy paste of a existing data frame.

I don't know how I could call this VB script from my python script and use it...

Duplicate Data Frame (Map) Utility

Any idea or suggestion is very welcome

Thank you in advance

Tags (2)
0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

Why not create a template mxd which contains a couple of dataframes which you can use .  You may not be able to create a dataframe, but there is nothing to stop you from using a template project...It does work and you can save it to a new one

MapDocument—Help | ArcGIS for Desktop

StephanieLassieur
New Contributor

Thank you for the reply, unfortunately I do need to have at the end of the process one mxd with as many dataframes as layers.

If I would create a template manually with many dataframes I would need to remove the empty ones, which is not possible in arcpy as far as I know

Any other idea?

Thank you in advance

0 Kudos
DarrenWiens2
MVP Honored Contributor

Rather than delete your unused data frames, move them off the page (elementPositionX and elementPositionY).

As for implementing ArcObjects through Python, it is somewhat difficult to get set up, but it can be done.

FreddieGibson
Occasional Contributor III

I don't remember there being a method available that would allow you to delete a dataframe. If someone has come across a method that allows this please mention so that I can look into it.

According to my understanding of arcpy, there aren't any methods available for creating content, such as Map Documents, Data Frames, Layout Elements, etc. I've seen most users leverage the workflow noted by Darren Wiens​. Typically they create a map with all of the content they'd require manually and use arcpy to manipulate content. For items like data frames and layout elements the approach is usually to move those items off the screen until they're needed.

If you want to easily accomplish this task you'd want to leverage ArcObjects via .NET or Java. The python approach is possible, but you won't find any supported channels from esri that would show you this approach. If I had to execute this task I would write up a console application or gp tool in ArcObjects. I could execute either of these items from python without too much trouble to create the needed content and them leverage arcpy to further manipulate the content.

Do you have anyone available within your organization that is familiar with ArcObjects?

DanPatterson_Retired
MVP Emeritus

Since there is no reference to creating a map, I would presume that moving elements off the layout isn't necessary. 

There are also no capabilities in the new arcpy.ma module either Introduction to arcpy.mp—ArcPy | ArcGIS for Desktop

except for the ability to import other *.mxd files to create a 'map' which potentially means you could create a template project and import it in a couple of times, if having a couple of dataframes languishing around empty is too much.  Of course, there is the ArcObjects route.  Perhaps the new *.aprx files will follow in their grandparents path and allow for the creation of all kinds of useful objects using python rather than Avenue....time will tell

0 Kudos