Arcpy Dataframe

5778
11
09-07-2011 06:09 PM
PatrickFischer1
New Contributor III
Hi everyone, i'm trying to make a script that does the following

Pulls the coordinates from the active dataframe and inputs them into a polygon for a preselected feature class. In addition populates certain attribute fields from data saved in the MXD such as scale and creation date. Also there are some other particulars in the fields that I want calculate such as Producer, Notes, Product Type, Country Code. I've taken a look at Dataframe Extent under Arcpy and was wondering if it was possible to pull the current extent from the active dataframe. Looking at the example code I made a theory of using the "Current" command to pull the coordinates.

df = arcpy.mapping.ListDataFrames(mxd)[0]
newExtent = df.extent
newExtent.XMin, newExtent.YMin = -180.0, -90.0
newExtent.XMax, newExtent.YMax = 180.0, 90.0
df.extent = newExtent


That's the example code I found located at http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/DataFrame/00s300000003000000/  Any help and advice and help is greatly appreciated.
Tags (2)
0 Kudos
11 Replies
PatrickFischer1
New Contributor III
Not sure I quite understand what you are looking for. You mean just a table of the data frame names?


That's pretty much what i'm looking for. A table that you can select which data frame you want to take the extent from.
0 Kudos
deleted-user-1T_bOHag6M8d
Occasional Contributor
That's pretty much what i'm looking for. A table that you can select which data frame you want to take the extent from.


You could retrieve the dataframes, print them as a list of options for the user and then get the user's response via "raw_input". However, I don't know if this will work when the script is used in an ArcToolbox.

I envision it something like this:

# Get a list of dataframes in the mxd and assign the list to df
dataFrames = arcpy.ListDataframes(mxd)

# Give each dataframe in the df list a number starting with 1 using enumerate and make it a dictionary
options = dict(enumerate(dataFrames, 1))

# Show options and let the user select which dataframe
response = int(raw_input("Select the number of the dataframe you want: %s \n" % options.items()))

# Assign df to the user's choice
df = options[response]



If you use that code you may want to build in some try:except clauses to send user-friendly error messages if bad info is entered.
0 Kudos