Data driven pages: rotate two data frames

535
2
Jump to solution
12-19-2012 04:34 PM
SamCoggins1
New Contributor III
Hi

I have a map with two data frames, DFA and DFB. I have used data driven pages with DFA to provide location, scale, and rotation for the data frame. With DFB I have used the data frame properties (link to another data frame's extent) to link DFB to DFA to show the same location, and the same scale. All good so far. However, now I'm stuck trying to find a way to use the rotation of DFA (provided by the attribute table) with DFB. I have found a script on the forum, but keep getting errors:

import arcpy mxd = arcpy.mapping.MapDocument("My_MAP") mainDF = arcpy.mapping.ListDataFrames(mxd, "DFA") locatorDF = arcpy.mapping.ListDataFrames(mxd, "DFB")  for DDP_Page in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = DDP_Page Rotate = mxd.dataDrivenPages.pageRow.Rotate #where Rotate is the name of the field in the attribute with the rotation values   locatorDF.rotation = Rotate


The script fails at the locatorDF.rotation = Rotate line. I'm not sure if I need to go beyond this script to achieve what I want. I have made other scripts that simply export each data frame as a pdf. However, I want to simply rotate DFB to the same angle as DFA, then export the entire map as a pdf. I have added an extra piece of code to export to pdf. Any help would be much appreciated. I'm getting better with Python, but it still takes me some time to get a script up and running.

Thanks in advance.

Sam
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JeffBarrette
Esri Regular Contributor
The 2 immediate issues I see is that 1) you don't have [0]'s after your list functions and 2) you have a for loop but no indentation.

import arcpy mxd = arcpy.mapping.MapDocument("My_MAP") mainDF = arcpy.mapping.ListDataFrames(mxd, "DFA")[0] locatorDF = arcpy.mapping.ListDataFrames(mxd, "DFB")[0]  for DDP_Page in range(1, mxd.dataDrivenPages.pageCount + 1):   mxd.dataDrivenPages.currentPageID = DDP_Page   Rotate = mxd.dataDrivenPages.pageRow.Rotate #where Rotate is the name of the field in the attribute with the rotation values     locatorDF.rotation = Rotate


Another way to do this is to get the rotation property value from one DF and apply to the other.  For example,

locatorDF.rotation = mainDF.rotation


You are not exporting or saving so your current code won't show immediate results.

There is an enhancement request on "link to another data frame's extent" to automatically include rotation.

Jeff

View solution in original post

0 Kudos
2 Replies
JeffBarrette
Esri Regular Contributor
The 2 immediate issues I see is that 1) you don't have [0]'s after your list functions and 2) you have a for loop but no indentation.

import arcpy mxd = arcpy.mapping.MapDocument("My_MAP") mainDF = arcpy.mapping.ListDataFrames(mxd, "DFA")[0] locatorDF = arcpy.mapping.ListDataFrames(mxd, "DFB")[0]  for DDP_Page in range(1, mxd.dataDrivenPages.pageCount + 1):   mxd.dataDrivenPages.currentPageID = DDP_Page   Rotate = mxd.dataDrivenPages.pageRow.Rotate #where Rotate is the name of the field in the attribute with the rotation values     locatorDF.rotation = Rotate


Another way to do this is to get the rotation property value from one DF and apply to the other.  For example,

locatorDF.rotation = mainDF.rotation


You are not exporting or saving so your current code won't show immediate results.

There is an enhancement request on "link to another data frame's extent" to automatically include rotation.

Jeff
0 Kudos
SamCoggins1
New Contributor III
Hi Jeff

Thanks for the reply. I've looked over the 'link to another data frame'. I don't see how to include rotation, could you be more specific? It would be nice to have for future reference.

I did follow your suggestions for the code I provided. The lack of indent was simple copy/paste error on my part when posting. I was getting an error saying the [0] was causing a problem, so I removed it. I found another piece of code online, have added the [0]'s back in, now there seems to be no problem and the code is working perfectly. Thanks for your help.

import arcpy
mxd = arcpy.mapping.MapDocument(r"G:\WORKSPACE\Test.mxd")
ddpDF = arcpy.mapping.ListDataFrames(mxd, "Top")[0] #Replace name of DDP Data Frame
otherDF = arcpy.mapping.ListDataFrames(mxd, "Bottom")[0] #Replace name of Other Data Frame you want to rotate
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    otherDF.rotation = ddpDF.rotation
    arcpy.mapping.ExportToPDF(mxd, r"G:\WORKSPACE\Page_" + str(pageNum) + ".pdf")
del mxd
0 Kudos