1

Is there a method to simply progress from one data driven page to the next in a script? Essentially, like pressing the "Next Page" button on the toolbar. I have started with:

import arcpy
mxd = arcpy,mapping.mapdocument ("Current") # or should I reference the mxd directly?
ddp = mxd.datadrivenpages
cp  = ddp.currentPageID
np  = cp + 1              #Advance to next PageID?
arcpy.RefreshActiveView()

But cannot seem to find a way to advance to the next page, most searches yield methods to only export the pages.

The end goal is to build a tool that advances to the next data driven page and selects all features in a layer that has a page definition set to match the index. This will facilitate attribute editing for the selected features.

The image below shows the selection model which works just fine, I just need to be able to script something to move forward a page and then run the Model (or script it all) to simplify the process.

enter image description here

  • 1
    Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. – Midavalo Jul 7 '17 at 15:48
2

You're assigning an integer value to a variable, not to your data driven pages. You are setting np = cp + 1, so, for example, if your current page is 2 then:

np = cp + 1

will return

np = 3

but np doesn't actually mean or do anything.

Instead you need to set mxd.dataDrivenPages.currentPageID = mxd.dataDrivenPages.currentPageID + 1 (or mxd.dataDrivenPages.currentPageID = cp + 1)

import arcpy
mxd = arcpy.mapping.MapDocument ("Current") 
ddp = mxd.dataDrivenPages
ddp.currentPageID += 1
arcpy.RefreshActiveView()

As an aside, double-check all your code for correct syntax/caps/formatting. There are a lot of typos in your code snippet above that I had to fix to test. A comma , instead of a period . and several lowercase letters mxd.datadrivenpages instead of mxd.dataDrivenPages etc. Python is VERY picky on these points!

  • Corrections per your comments do indeed make the script work. Your are correct that Python is very picky, I usually make those simple mistakes and scratch my head until I notice them. Thank you. – SMS Jul 10 '17 at 14:10

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.