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.
-
1Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format.Midavalo– Midavalo ♦2017年07月07日 15:48:48 +00:00Commented Jul 7, 2017 at 15:48
1 Answer 1
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– SMS2017年07月10日 14:10:31 +00:00Commented Jul 10, 2017 at 14:10