2

I've read a lot about the topic data driven pages. I'm writing a python script for ArcGIS and I've defined my stripmap using the arcpy.StripMapIndexFeatures_cartography command and now I have to set up Data Driven Pages with all the parameters it needs. My only problem is that I cannot understand how to do this. Is there a specific command in the arcpy library or a specific workaround to do this?

2

If you have not already gone through the ESRI arcpy.mapping tutorials and ArcGIS Resources pages, they have heaps of sample scripts to comb through. I would suggest looking at these first:

Tutorials:

If you are using 10.0, you can find similar help topics for it on the 10.0 help site.

| improve this answer | |
  • Hi Ryan, and thanks for answering.. my exact problem is that the tutorial itself says: "Data Driven Pages must first be enabled and authored within a map document (.mxd) using the Data Driven Pages toolbar in ArcMap before it can be referenced with arcpy.mapping." – Annalisa Minelli Oct 7 '12 at 14:43
  • well.. now I'm trying to write a script to automatize everything - but I cannot - from how it seems. And maybe now I will be forced to stop my script at a certain point and say the user: "please, open the ddp setup and set this parameter in this way - this other in this way.." which is near horrible to me. But it seems there's no other way if I can't ENABLE data driven pages from arcpy, or arcpy.mapping.. or wahtever it is :( – Annalisa Minelli Oct 7 '12 at 14:46
  • Hi! Do you have any update or solution on this issue? Is there a way to automate everything, including "enabled and authored within a map document (.mxd) using the Data Driven Pages toolbar in ArcMap" you mentioned? Thanks! – Energetic Codfish Mar 18 '19 at 14:42
1

You can largely avoid opening the reference mxd by using layers. This is generally how arcpy.mapping operates anyways, is through layer files.

For example, I have used a workflow which looks something like this:

  • arcpy.MakeFeatureLayer_management - here is where you can subset the data
  • arcpy.SaveToLayerFile_management
  • arcpy.mapping.UpdateLayer - allows you to switch out an existing layer in the mxd with the one you have created for your needs
  • arcpy.mapping.DataDrivenPages.refresh()
| improve this answer | |
1

The right answer is you can't create or set up DataDrivenPages using arcpy at all. Most up-voted general answer to read documentation is helpful only to the point that you can find in it:

"The reverse is also true: map series can be completely scripted using arcpy.mapping without using the Data Driven Pages user interface in ArcMap, but there are good reasons for combining both techniques."

It might sound like you can create such object, right? Well you have to read more to get slapped:

"Data Driven Pages must first be enabled and authored within a map document (.mxd) using the Data Driven Pages toolbar in ArcMap before it can be referenced with arcpy.mapping."

If you look at the class itself, apart "currentPageID" the rest of few properties it has are Read Only. Few methods available will also not help you to set any property at all. The workaround is to program everything yourself without using data driven pages at all.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.