I'm customizing an automated mapping method using arcpy.mapping and data driven pages.
Essentially I have a script that loops through each page, and modifies the location of the inset map, legend, and other map or graphic elements.
I've got everything working, except for some maps, it is necessary to change the extent of the main dataframe so that the inset map, or legend does not overlap with the region of interest. As an example, the data frame may need to shift 500 metres North and East, so that there is no overlap. This is what I can't get to work.
I'm using a for loop, with conditional statements to make the necessary adjustments. An example condition is:
if (pgIndex == 4):
# Set position of the Legend
elLeg = arcpy.mapping.ListLayoutElements(tempMap,"LEGEND_ELEMENT", "")[0]
elLeg.elementPositionX = 0.0186
elLeg.elementPositionY = 0.4124
# Move scalebar
scaleBar = arcpy.mapping.ListLayoutElements(tempMap, "MAPSURROUND_ELEMENT", "Alternating Scale Bar")[0]
scaleBar.elementPositionX = 0.1
scaleBar.elementPositionY = 0.1
#Move North Arrow
NorthArrow = arcpy.mapping.ListLayoutElements(tempMap, "MAPSURROUND_ELEMENT", "North Arrow")[0]
NorthArrow.elementPositionX = 0.75
NorthArrow.elementPositionY = 0.1
#Move Legend NeatLine
Neatline = arcpy.mapping.ListLayoutElements(tempMap, "GRAPHIC_ELEMENT", "")[0]
Neatline.elementPositionX = 0
Neatline.elementPositionY = 0
#Move inset map position
inset = arcpy.mapping.ListDataFrames(tempMap, "LocatorDF")[0]
inset.ElementPositionX = 0
inset.ElementPositionY = 3.25
#Set extent for main data frame (THIS IS WHAT IS NOT WORKING)
mainMap = arcpy.mapping.ListDataFrames(tempMap, "MainDF")[0]
extent_4 = arcpy.Extent(423017.450685167,4991568.14747271,438257.481165228,4976328.11699265)
mainMap.extent = extent_4