Setting DF inset window not behaving right?

1719
3
04-28-2011 08:34 AM
RyanKelley
New Contributor II
I have two data frames. One is an inset map.

I want my inset map to have the same extent as my main data frame... this works just fine in the arcpy window, but not in my script. Pretty straightforward, but not sure why it's not working... any ideas?

DF = MAP.ListDataFrames(MXD)[0]
newInsetExtent = DF.extent
DF_inset = MAP.ListDataFrames(MXD)[1]
DF_inset.extent = newInsetExtent
DF_inset.scale = 1500000

My Map ends up with the correct scale of 1500000, but my extent never gets passed. Again, this works perfectly fine in the arcpy window.

thanks,
ryan
0 Kudos
3 Replies
JeffBarrette
Esri Regular Contributor
Ryan,

I could not reproduce.  There are a couple of things.

1) The aspect ratio of your data frames need to be similar otherwise the extents can not be the same - we don't warp the data but fit the extent until the one of the delta Xs or Ys are fitted.

2) did you save your changes?

Here is my code - I have a simple MXD with 2 data frames, the main is 6x6 inches and the inset is 2x2 inches.

import arcpy
MXD = arcpy.mapping.MapDocument(r"C:\Temp\df.mxd")
DF = arcpy.mapping.ListDataFrames(MXD, "main")[0]
newInsetExtent = DF.extent
DF_inset = arcpy.mapping.ListDataFrames(MXD, "inset")[0]
DF_inset.extent = newInsetExtent
MXD.saveACopy(r"C:\Temp\df2.mxd")
0 Kudos
RyanKelley
New Contributor II
Hi Jeff,

I see a mistake in my desciption of my issue: "I want my inset map to have the same extent as my main data frame" should be "I want my inset map to have the extent indicator in the center of my inset data frame at 1:1,500,000." So, my logic here was just use the same DF.extent as my main DF, then just zoom out to 1:1,500,000.

I have never been able to use wildcards when using arcpy.mapping.ListDataFrame ie. "main" and "inset". I get "Runtime error <type 'exceptions.IndexError'>: list index out of range." I have always had to declare them through a list: [0], [1], etc.

Any additional thoughts?

thanks,
ryan
0 Kudos
RyanKelley
New Contributor II
Having this code at the very end of the script (before my PDF export) made this work properly. Maybe because I was going back and forth between Data Frames just once, it was messing something up? The code below workd just fine.

Thanks again for your input Jeff...

import arcpy.mapping as MAP
DF = MAP.ListDataFrames(MXD)[0]
...code...
newInsetExtent = DF.extent
DF_inset = MAP.ListDataFrames(MXD)[1]
DF_inset.extent = newInsetExtent
DF_inset.scale = 1500000
0 Kudos