Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Trying to combine 3 variables to export data driven page by page name

$
0
0
I am trying to write a Python script so the user can export a PDF map from an MXD using data driven pages without the user having to open the MXD and scroll through all the data driven pages to find the page they need. The Index Grid is the Section, Township, Range polygon. The page name looks like this in the attribute table: T1N R70W S12.

In order to make it easier for the user, I broke up the STR into 3 separate parameters that have value lists so they can just pick their value from a drop down. The parameters are strings. I'm running into problems trying to combine the 3 parameters into 1 string so the data driven pages can get the page ID from the page name. The script runs with no errors, however, it also exports the firstpage in the mxd. I can't get it to use the user defined parameters to identify the page name. I believe the issue is in line 23.

Here is the script:

# Setup
# Import arcpy module
import sys, string, os, arcpy
from arcpy import env
from arcpy import mapping
from os import sep as bs

# Script arguments
FOLDER = arcpy.GetParameterAsText(0)
TNSHP = arcpy.GetParameterAsText(1)
RNG = arcpy.GetParameterAsText(2)
SCTN = arcpy.GetParameterAsText(3)

#Set workspace
arcpy.env.overwriteOutput = True
outPath = FOLDER + bs
arcpy.env.workspace = outPath

# Select and Zoom to Section Township Range
mxd = mapping.MapDocument(r"V:\gislu\_BasemapMXD\Assessor24x36.mxd")
ddp = mxd.dataDrivenPages
arcpy.AddMessage("Finding Township Range Section")
newpage = TNSHP + " " + RNG + " " + SCTN
pageID = ddp.getPageIDFromName(newpage)
ddp.currentPageID = pageID

#Export PDF
finalPdf = outPath + "T" + TNSHP + "R" + RNG + "S" + SCTN + "ParcelMap.pdf"
arcpy.AddMessage("Exporting PDF")
ddp.exportToPDF(finalPdf, 'CURRENT', resolution = 200)
arcpy.AddMessage("DONE!")

del mxd, finalPdf, ddp, pageID

Viewing all articles
Browse latest Browse all 2485

Trending Articles