Select to view content in your preferred language

Data Driven Pages-Restrict Indexed Feature

1663
12
06-24-2011 11:00 AM
BarbaraMcIntosh
New Contributor
I'm creating a series of Data Driven pages at a fixed scale of 1:12000.  I have multiple features in my index layer that, at that scale, appear within the data frame.  I'd like to be able to restrict the feature that appears within the data frame to only the one feature defined by the indexing for that page.  Is there an easy way to do this?  Used to be able to do this in DSMapbook by clicking "Restrict display to active feature"
0 Kudos
12 Replies
JasonMoore
Emerging Contributor
It dropped the indentation, so be careful.  Sorry.
0 Kudos
JeffBarrette
Esri Regular Contributor
Just as an FYI.  If you highlight your code and click the # button it will wrap your code in special CODE tags so you don't lose the python indentation.  For example - not 100% sure I got your indents correct:

# Import Modules
import arcpy, os

# Set Variables
mxdpath = r'FULL PATH TO MXD FILE' # string 
outputfolder = 'FULL PATH TO OUTPUT FOLDER' # string 
namefield = 'THE FIELD CONTAINING THE NAME OF THE RESULTING PDF FILE' # string 
queryfield = 'THE FIELD CONTAINING THE VALUE FOR THE DESIRED QUERY' # string 
layers = ['LIST','OF','LAYERS'] # list

mxd = arcpy.mapping.MapDocument(mxdpath)
# Start Loop through Data Driven Pages
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1)
    mxd.dataDrivenPages.currentPageID = pageNum # set the current page
    pageName = mxd.dataDrivenPages.pageRow.getValue(field) # get the pageName
    pageName += '.pdf' # add '.pdf' extension for file name
    pdf = os.path.join(outputfolder, pageName) # add pageName to output folder to get full output path
    # Start Loop through all layers of mxd file
    for lyr in arcpy.mapping.ListLayers(mxd) # for every layer in mxd's Layer List
        if lyr.name in layers: # if layer name in user input list above
            value = mxd.DataDrivenPages.pageRow.getValue(queryfield) # get value of query field
            if lyr.defintionQuery == True: # if a defintionQuery Exsts...
                query = lyr.defintionQuery + "AND QueryField = \'%s\'" % (value) # Add new to old
            else:
                query = "QueryField = \'$s\'" % (value) # else create a new query
                lyr.defintionQuery = query # set the layers defintionQuery
        else:
            print 'Next' # else print next, this isn't necassary, but its a good place holder

arcpy.mapping.ExportToPDF(mxd, pdf) # export the current Page to pdf
del mxd, lyr, pageName, pageNum, query, value 
0 Kudos
JasonMoore
Emerging Contributor
Thank you, that is nice to know.
0 Kudos