AnsweredAssumed Answered

Can Python respond to events? Want to fix data frame rotation issue.

Question asked by ameador1 on Jul 13, 2012
Latest reply on Jul 17, 2012 by ameador1
I have read through some posts and found some Python code to help but it's not quite where I need it.

I am usind Data Driven Pages (DDP) with two data frames in ArcMap (ArcEditor) 10.1. The layout has two data frames. The first data frame ("Layers") is where parcels are drawn with annotation etc... The seond data frame ("Shadow") sits over "Layers" and shows only the parcel lines from the 'maps' surrounding the active 'map' in grey - with no annotations. Some of the 'maps' have to be rotated to fit properly and that is handled with a field called Rotation in the DDP index layer (DistMap in my case). So, when I move from page to page in the DDP toolbar, then "Layers" data frame rotates properly, but the "Shadow" data frame does not. "Shadow" data frame sets it's extent and scale from the "Layers" data frame - but ArcDesktop is lacking an option to also have the "Shadow" data frame to match the Rotation of the other data frame.

So I have found posts on this topic, but not the solution I'm looking for. I want the rotation to happen for the "Shadow" data frame when I move from page to page in the DDP toolbar. Code that I have found/modified so far is:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
topDF = arcpy.mapping.ListDataFrames(mxd, "Layer")[0]
bottomDF = arcpy.mapping.ListDataFrames(mxd, "Shadow")[0]

for DDP_Page in range(1, (mxd.dataDrivenPages.pageCount)):
>>>>mxd.dataDrivenPages.currentPageID = DDP_Page
>>>>angle = mxd.dataDrivenPages.pageRow.getValue("MapGrid.Rotation") # Make sure to use the table.field format to work correctly
>>>>bottomDF.rotation = angle
>>>># arcpy.mapping.ExportToPDF(mxd, r"C:\project\Map_20k_B" + str(DDP_Page) + ".pdf") # Add this line to export the data page - rotated for pdf file

But, the problem here is that the last data driven page pagerow record sets the angle used by the mxd current map document - not the individual data pages in the data driven pages. So, then when you iterate through the data driven pages with the DDP, after running this script, the last angle used on the last DDP page is used for all the pages.

I'm thus thinking that the way to solve this would be to attach to an event - like a DDP_PageChanged type of event to call the Python code to change the page rotation as the pages are navigated in the DDP toolbar. I also understant that VBA support is going away and I need a solution that will work down the line. Is there a way to do this?

I have been using ArcGIS software for about 5 years now (since 9.2) - so I am pretty familiar with the software - but I don't have much experience coding with VBA or Python for things like this. My main coding in Arc stuff has been using VBA for labeling feature classes. I took a class in ArcObjects for .NET a coupole of years ago - however it was a broken course - mostly taught on VB6 - COM methods instead of .NET and the part covering setup of installers for your tools was covered extremely fast and brushed over - so if I have to create a new tool of do this with .NET verses VBA or Python - that's fine, but will need pretty detailed help.

Thanks!

Outcomes