Matching Rotation Between Data Frames Using Data Driven Pages

2717
10
Jump to solution
03-12-2012 03:38 PM
AdamInglis
Occasional Contributor II
I've created a DataDriven Pages (DDP) MXD with two main data frames of a proposed road.  I want both data frames to have the same extents and the same rotation.  The top data frame is controlled by DDP and the rotation is set by a field in the Strip Map Index.  I've set the bottom data frame to match the extents of the top data frame through the Data Frame Properties > Data Frame tab, however, there is no option to match the rotation to the top data frame.  So I turned to python and hacked together a simple script to set the rotation of the bottom data frame to match the top data frame:

import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") topDF = arcpy.mapping.ListDataFrames(mxd, "Top")[0] bottomDF = arcpy.mapping.ListDataFrames(mxd, "Bottom")[0]  for DDP_Page in range(1, (mxd.dataDrivenPages.pageCount + 1)):     mxd.dataDrivenPages.currentPageID = DDP_Page     angle = mxd.dataDrivenPages.pageRow.angle      bottomDF.rotation = angle


The problem with the above script is that it overwrites bottom data frame's rotation setting with every iteration through the for loop.  So after running the script, the rotation of the bottom data frame on every page is set to the rotation of the last page of the top frame.  I suppose one way around this might be to export out a PDF within the FOR loop.  Any other suggestions?
1 Solution

Accepted Solutions
AdamInglis
Occasional Contributor II
Thanks Jeff.  I did just end up using the script to export the PDFs from within the FOR Loop with:
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") topDF = arcpy.mapping.ListDataFrames(mxd, "Top")[0] bottomDF = arcpy.mapping.ListDataFrames(mxd, "Bottom")[0]  for DDP_Page in range(1, (mxd.dataDrivenPages.pageCount + 1)):     mxd.dataDrivenPages.currentPageID = DDP_Page     angle = mxd.dataDrivenPages.pageRow.angle      bottomDF.rotation = angle     arcpy.mapping.ExportToPDF(mxd, r"C:\project\Map_20k_B" + str(DDP_Page) + ".pdf")

View solution in original post

0 Kudos
10 Replies
JeffBarrette
Esri Regular Contributor
Wouldn't this only be the case if you save the MXD?  If the objective is to export to PDF, then run the script, export, and don't save changes.  This tool may be better off running as a script tool where you can enter an index value and have it just export that page (or a range of pages).

It would be a good idea to added match data frame rotation to the ideas.esri.com site.

Jeff
0 Kudos
AdamInglis
Occasional Contributor II
Thanks Jeff.  I did just end up using the script to export the PDFs from within the FOR Loop with:
import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") topDF = arcpy.mapping.ListDataFrames(mxd, "Top")[0] bottomDF = arcpy.mapping.ListDataFrames(mxd, "Bottom")[0]  for DDP_Page in range(1, (mxd.dataDrivenPages.pageCount + 1)):     mxd.dataDrivenPages.currentPageID = DDP_Page     angle = mxd.dataDrivenPages.pageRow.angle      bottomDF.rotation = angle     arcpy.mapping.ExportToPDF(mxd, r"C:\project\Map_20k_B" + str(DDP_Page) + ".pdf")
0 Kudos
richardBurdett
New Contributor II
This is Exactly what I need.

I have the same problem i have a road with two data frames that need to match exactly both DDP and rotation for each page exported. How can I modify this script to assist me?

Thanks!
0 Kudos
richardBurdett
New Contributor II
Wouldn't this only be the case if you save the MXD?  If the objective is to export to PDF, then run the script, export, and don't save changes.  This tool may be better off running as a script tool where you can enter an index value and have it just export that page (or a range of pages).

It would be a good idea to added match data frame rotation to the ideas.esri.com site.

Jeff


I was wondering if you could edit the scripf tor me so I could add a page range?

Its a lot to aks I know but my Python is poor at best.

Kind regards,

RB
0 Kudos
JeffBarrette
Esri Regular Contributor
I was wondering if you could edit the script for me so I could add a page range?


The script example in the post is simply exporting each page in the for loop (with custom logic executed at each page).  Rather than exporting all pages, modify the range value.

Change:
for DDP_Page in range(1, (mxd.dataDrivenPages.pageCount + 1)):

To:
for DDP_Page in range(2, 5)):


This will print pages 2-4.

The second sample script for the DDP help topic shows how you can export a list of page names.
http://resources.arcgis.com/en/help/main/10.1/#/DataDrivenPages/00s300000030000000/

Jeff
OrkhanAbdullayev
New Contributor III

Hi Jeff,

I found only this 7 years old topic when I tried to find the answer about DDP setting rotation angle.

Can you help me with this? 

My exactly question is: I have single layout with 4 data frames (A,B,C,D). In layout mode I enabled DDP and set the rotation angle column from attribute table for data frame A. When I drive pages in layout other data frames moves as well but does not have the rotation angle as I have in frame A. Is it possible to have the same rotation angle for all frames when I change pages?

Thank you for your valuable time and response.

0 Kudos
JeffBarrette
Esri Regular Contributor

Orkhan,

It is the same code as the original script but you are just referencing additional data frames.

import arcpy mxd = arcpy.mapping.MapDocument("CURRENT")
Main_DF = arcpy.mapping.ListDataFrames(mxd, "Main DF")[0]
DF_B = arcpy.mapping.ListDataFrames(mxd, "B")[0]
DF_C = arcpy.mapping.ListDataFrames(mxd, "C")[0]
DF_D = arcpy.mapping.ListDataFrames(mxd, "D")[0]
for DDP_Page in range(1, (mxd.dataDrivenPages.pageCount + 1)):
    mxd.dataDrivenPages.currentPageID = DDP_Page
    angle = mxd.dataDrivenPages.pageRow.angle
    DF_B.rotation = angle
    DF_C.rotation = angle
    DF_D.rotation = angle

OrkhanAbdullayev
New Contributor III

Jeff,

" arcpy.mapping.ListDataFrames(mxd, "Main DF")[0] "

Above shown line gave error, couldn't figure out what can be the issue in that line?

I simply copy you code to python window of arcmap and tried to run (only changed layer name from A to Morphology, B to Contour) 

0 Kudos
JeffBarrette
Esri Regular Contributor

"Main DF" is a wildcard search for the name of the data frame.  You may be searching for a data frame with a different name.