POST
|
Hi Jeff, I'm currently working on a script for exporting ddp with a mask layer and I'm having trouble getting the definition query to update for each page as it exports. I'd appreciate it if you could take a look and provide suggestions. Here's the script:
import arcpy, sys, os
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
print "Enter save as pdf location:"
pdfDir = arcpy.GetParameterAsText(0)
outputFolder = pdfDir + r"\PDFs"
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
maskLayer = arcpy.mapping.ListLayers(mxd, "state_bnd110", df)[0]
maskField = "STATE_NAME"
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
pageName = mxd.dataDrivenPages.pageRow.STATE_NAME
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == maskLayer:
lyr.definitionQuery = '"STATE_NAME" <> %s' % pageName
arcpy.RefreshActiveView()
arcpy.mapping.ExportToPDF(mxd, os.path.dirname(outputFolder)+ os.sep + pageName + ".pdf")
del mxd
arcpy.GetMessages()
Thanks, Karla
... View more
03-22-2012
09:22 AM
|
0
|
0
|
1214
|
POST
|
Okay, I gave that a try and now I'm getting a Runtime Error after it exports the first ddp. type 'exceptions.RuntimeError'>: LayerObject: Set attribute definitionQuery does not exist Failed to execute
... View more
03-21-2012
09:55 AM
|
0
|
0
|
1246
|
POST
|
Thanks for the suggestion, that solved the problem of exporting the ddp with the mask symbology. Unfortunately, it's still looping through the same state (the first one, Arizona) over and over again without moving on to the next page in the ddp.
... View more
03-21-2012
09:15 AM
|
0
|
0
|
1246
|
POST
|
Thank you for replying with that information! I couldn't figure out how to get my script to post with the indentations intact. Here it is again, complete with indentations:
import arcpy, sys, os
arcpy.OverWriteOutput = 1
mxd = arcpy.mapping.MapDocument("CURRENT")
print "Enter save as pdf location:"
pdfDir = arcpy.GetParameterAsText(0)
outputFolder = pdfDir + r"\PDFs"
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
maskLayer = arcpy.mapping.ListLayers(mxd, "state_bnd110", df)[0]
maskField = "STATE_NAME"
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
pageName = mxd.dataDrivenPages.pageRow.STATE_NAME
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == maskLayer:
lyr.definitionQuery = '"STATE_NAME" <> pageName'
arcpy.mapping.ExportToPDF(mxd, os.path.dirname(outputFolder)+ os.sep + pageName + ".pdf")
lyr.definitionQuery = ""
arcpy.RefreshActiveView()
del mxd
arcpy.GetMessages()
... View more
03-21-2012
07:53 AM
|
0
|
0
|
1246
|
POST
|
I'm hoping someone can help me with this one; I've read every post I could find and I'm still stuck. I've got a series of data driven pages that I can get to export with no problem, but I also need to update a mask layer while I'm exporting each page. The ddp name is based on state names and the mask layer is also based on state name. I've got a simple definition query that I use to turn the mask layer on and off for each state. For example, the current ddp is Arizona so the definition query on the mask layer would be "STATE_NAME" <> 'Arizona'. This turns the mask layer off for Arizona while leaving the surrounding states grayed out. Here's the script that I have so far: import arcpy, sys, os arcpy.OverWriteOutput = 1 mxd = arcpy.mapping.MapDocument("CURRENT") print "Enter save as pdf location:" pdfDir = arcpy.GetParameterAsText(0) outputFolder = pdfDir + r"\PDFs" df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] maskLayer = arcpy.mapping.ListLayers(mxd, "state_bnd110", df)[0] maskField = "STATE_NAME" for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): mxd.dataDrivenPages.currentPageID = pageNum pageName = mxd.dataDrivenPages.pageRow.STATE_NAME for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name == maskLayer: lyr.definitionQuery = '"STATE_NAME" <> pageName' arcpy.mapping.ExportToPDF(mxd, os.path.dirname(outputFolder)+ os.sep + pageName + ".pdf") lyr.definitionQuery = "" arcpy.RefreshActiveView() del mxd arcpy.GetMessages() If I take out the layer loop the script will export all the ddp with no trouble (and with no mask symbology). As the script is now, it will export the first state (Arizona) with all the states grayed out (for this page, Arizona should not be) then it will export Arizona again and again. Any help would be greatly appreciated! Karla
... View more
03-20-2012
03:09 PM
|
2
|
12
|
7427
|
Title | Kudos | Posted |
---|---|---|
2 | 03-20-2012 03:09 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|