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

Midavalo
30k11 gold badges53 silver badges108 bronze badges
asked Jul 7, 2017 at 15:46
1
  • 1
    Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format. Commented Jul 7, 2017 at 15:48

1 Answer 1

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!

answered Jul 7, 2017 at 16:00
1
  • 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. Commented Jul 10, 2017 at 14:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.