This content has been marked as final. Show 9 replies
I think your problem might be your clause string. I tried typing the same text in the Python window and got a runtime error. What do you want the clause value to be?
Scratch that, I needed to create the STR variable.
I don't think you need to go through all of the selection code. If you replace "SEC_FULL" with the STR variable, it should change to the section entered by the user.
pageID = ddp.getPageIDFromName(STR) ddp.currentPageID = pageID
Then you can get rid of all of the selectLayerByAttribute_management code.
As long as the user enters the section correctly it should work. You might want to put some error handling code in to make sure they type the section correctly.
You will also want to use os.remove(tmpPdf) to delete the temporary pdf file. The del command is for object cleanup which you have a bunch of - ddp, df, Layer, and mxd. Where you don't need to do the layer selection, I think the only objects you need are the mxd and ddp objects.
#Import arcpy module import string import arcpy import os from arcpy import mapping from os import sep as bs # Script arguments STR = arcpy.GetParameterAsText(0) #Export Section Map mxd = arcpy.mapping.MapDocument(r"V:\gislu\Planning\DeveloperKit\SectionMap.mxd") ddp = mxd.dataDrivenPages pageID = ddp.getPageIDFromName(STR) ddp.currentPageID = pageID tmpPdf = r"V:\gislu\Planning\DeveloperKit\output\Section_temp.pdf" ddp.exportToPDF(tmpPdf, 'CURRENT', resolution = 175) finalPdf.appendPages(tmpPdf) os.remove(tmpPdf) del mxd, ddp
probably won't work because finalPdf isn't defined. I am assuming you have it defined in code that you didn't include in your post.
Thanks Jeff. I do have the os.remove(tmpPDF) command at the end of the script to remove all of the temporary pdfs. I also have defined the finalPDF at the beginning of the script which I did not include. I tried your suggestion of removing the selection piece and replacing the SEC_FULL with the STR parameter. This is what the new code section looks like:
#Select and Zoom To Section Map, Export, and Append
mxd = arcpy.mapping.MapDocument(r"V:\gislu\Planning\DeveloperKit\SectionMap.mxd")
df = mapping.ListDataFrames(mxd, "STR Map")
ddp = mxd.dataDrivenPages
pageID = ddp.getPageIDFromName(STR)
ddp.currentPageID = pageID
tmpPdf = r"V:\gislu\Planning\DeveloperKit\output\Section_temp.pdf"
ddp.exportToPDF(tmpPdf, 'CURRENT', resolution = 175)
del mxd, tmpPdf, ddp
I typed the user defined parameter exactly the same way it is shown in the SEC_FULL field in the attribute table. I got the following error:
<type 'exceptions.ValueError'>: u'T1S R70W S30'
Failed to execute (MapbookSection).
Any other suggestions?
Have you tried hard coding the text into the program? It may be a problem with getting the STR variable from the GetParameterAsText function.
pageID = ddp.getPageIDFromName('T1S R70W S30')
If that works maybe try placing your GetParameterAsText function in the str() function.
STR = str(arcpy.GetParameterAsText(0))
That worked! Thank you so much! The file size of the final mapbook is too large to attach. If you would like a copy of the entire script let me know. It writes a title page, TOC, vicinity map, section map, and several thematic maps zoomed in on a particular property and appends it into 1 PDF. We got the idea from Clark County, WA here: http://gis.clark.wa.gov/gishome/WebOrders/?pid=goDevPacket
There are a couple of already existing samples on the resource center:
There is one called Print Data Driven Page(s).