code for checking whether data driven pages enabled

205
4
04-01-2011 08:48 AM
ErinIverson
New Contributor II
Is there a means of checking, in Python, whether data driven pages are enabled in a particular MXD?

All the code and help I can find seems to imply this verification must take place manually, and if I call

mxd.dataDrivenPages


for a map document object that doesn't have DDP, I get an error.

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\mixins.py", line 447, in dataDrivenPages
    return convertArcObjectToPythonObject(self._arc_object.pageLayout.dataDrivenPages)
AttributeError: PageLayoutObject: Get attribute dataDrivenPages does not exist
Tags (2)
0 Kudos
4 Replies
StevenArebalo
New Contributor
Maybe creating a try that catches the specific AttributeError and informs the user? It really isn't checking for DDP enabled, but will provide the same end result.
0 Kudos
JasonScheirer
Regular Contributor II
Use either

if mxd.supports("dataDrivenPages"):

or

if hasattr(mxd, "dataDrivenPages"):
0 Kudos
JonPedder
Occasional Contributor II
Is it still the case that there isn't a way to turn DDP on/off within Python?
0 Kudos
AdhimoolamD
New Contributor
Hi

yes, the below code is working fine to check whether the DDP enabled in the MXD.
But the DDP can be enabled with only one Map Dataframe. in otherway, if the MXD have more than one Dataframe, then let me know the DDP enabled to which dataframe.

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Projects\Untitled_new.mxd")
if hasattr(mxd, "dataDrivenPages"):
    print "yes"
else :
    print "No"
0 Kudos