Turn On/Off Data Driven Pages in Script

306
3
10-08-2010 03:12 AM
AndyBell
New Contributor
Hi there,

I'm writing a script to select individual features in a user-defined area, and I need to use data driven pages to print each one with clipping. However I cannot find ANYWHERE the ability to turn on the datadriven pages. Surely there must be a way?  Every item I find when I google seems to assume datadrivenpages is already switched on when a script runs.

Can someone advise?
0 Kudos
3 Replies
JeffMoulds
Esri Contributor
You don't necessarily need DDP to do that. Your algorithm would be:

- use a search cursor to loop through the features you want to print
- use the methods and properties of the dataframe class to go to each area you want to print
- use the print/export functions

The code would look something like this:

rows = arcpy.SearchCursor(mLayer, "WoodyAreasClip.ProtectedStatus = " + repr(theStatus))
for row in rows:
        theOID = row.getValue(r"WoodyAreasClip.OBJECTID")
        arcpy.SelectLayerByAttribute_management(mLayer, "NEW_SELECTION", "WoodyAreasClip.OBJECTID = " + repr(theOID))
        DF.zoomToSelectedFeatures()
        arcpy.RefreshActiveView()
        # print it (or export it)    
        arcpy.mapping.ExportToJPEG(MXD, r"C:\temp" + "\\" + repr(theOID) + ".jpg")


You are correct - the code samples assume you have DDP turned on. There isn't a way to turn DDP on/off in Python. The following help topics touch on the differences between creating map books using python (like the example above) versus creating map books using DDP.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/DataDrivenPages/00s300000030000000/

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s90000002s000000.htm
0 Kudos
AdhimoolamD
New Contributor
Dear Jeff,

DDP is working with only one DF at atime. but we need to keep multiple dataframe in single page, so let me know what is the best approach to achive  this.

Reg,
AD
0 Kudos
JeffBarrette
Esri Regular Contributor
This topic is going off on a tangent from the original title but ...

Have you tried looking at the following help topic:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Customizing_your_map_extent/00s9000000...

Review the "Other Data Frame" section.

Jeff
0 Kudos