Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to use DDP (Data Driven Pages) and am running into a problem. I'm using arcpy.SelectLayerByAttribute_management to select a series of records, and then trying to use the ddp.exportToPDF(pdfddp, "SELECTED") but keep running into an error (below). It shouldn't be the select by attribute function as I run it in ArcMap and it runs correctly and I can see the selected features highlighted. Also, I can successfully use the ddp.exportToPDF(pdfddp, "CURRENT") but what I need is to be able to have a user select a series of features and have those be passed.

 mxd = arcpy.mapping.MapDocument("C:\\temp\\Graffiti_DM4.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
pdfddp="C:\\temp\\pdfddp1.pdf"
arcpy.SelectLayerByAttribute_management("C:\\temp\\test.lyr","NEW_SELECTION", '"Incident_Z" ='  + "'10002'")
ddp.exportToPDF(pdfddp, "SELECTED")

And here is the error

Runtime error 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\utils.py", line 181, in fn_
    return fn(*args, **kw)
  File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\_mapping.py", line 446, in exportToPDF
    return convertArcObjectToPythonObject(self._arc_object.exportToPDF(*gp_fixargs((out_pdf, page_range_type, page_range_string, multiple_files, resolution, image_quality, colorspace, compress_vectors, image_compression, picture_symbol, convert_markers, embed_fonts, layers_attributes, georef_info, jpeg_compression_quality, show_selection_symbology), True)))
AttributeError: PageLayoutObject: Error in exporting pages

As always, any help is EXTREMELY appreciated!

share|improve this question
    
I'm not 100% sure, but the "SELECTED" should be referring to the index/page features. It looks like a feature from the test.lyr is selected and not a index/page feature. I would try to use those selected features in test.lyr to do a SelectByLocation to fetch the index/page features that have incidences of interest. –  gm70560 Apr 24 '13 at 1:06
add comment

1 Answer 1

For once, I'll answer my own question!

It's not the exact answer to why the above doesn't work, but is a work around:

arcpy.env.overwriteOutput = 1
mxd = arcpy.mapping.MapDocument("C:\\temp\\Graffiti_DM4.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]

newlayer="C:\\temp\\newlayer.lyr"
newpointout="C:\\temp\\newpointout.shp"
newpointlayer="C:\\temp\\newpointlayer.lyr"
pdfddp="C:\\temp\\pdfddp1.pdf"
ddp = mxd.dataDrivenPages

arcpy.Select_analysis(newlayer, newpointout,"'ZIP' = '10004'")
arcpy.MakeFeatureLayer_management(newpointout, newpointlayer)
ddp.exportToPDF(newpointlayer, "ALL")

And it works!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.