The solution would need to include arcpy.mapping. Here is a great example in help where two different MXDs are used to handle facing pages (left and right pages use different layout settings). All pages are combined into one fine PDF using arcpy.mapping.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s90000002p000000.htm
Jeff
mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] lyr = arcpy.mapping.ListLayers(mxd)[0] rows = arcpy.SearchCursor(lyr.dataSource): for row in rows: newDFExt = row.getValue("Shape").extent df.extent = newDFExtent arcpy.mapping.ExportToPDF(mxd, somepath) del mxd
I tired, but didnt work. Something was wrong, i fixed, line 4, requires no colon : at the end
But still doesnt work. Changes the extent, but doesnt export pdf. What is wrong?
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd)[0]
rows = arcpy.SearchCursor(lyr.dataSource)
for row in rows:
newDFExt = row.getValue("Shape").extent
df.extent = newDFExt
arcpy.mapping.ExportToPDF(mxd, r"D:\TEMP\datadriven")
del mxd
Hello Raphael,
I apologize for the accidental (colon) typo. I should have tested the code first. I believe the issues you are running into has to do with your pdf output file. Because you are iterating through multiple features, you need to build the PDF to uniquely name each file. In the example below, I'm using the features "NAME" property and building the outputpath/filename.
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd)[0]
rows = arcpy.SearchCursor(lyr.dataSource)
for row in rows:
newDFext = row.getValue("Shape").extent
df.extent = newDFext
somepath = "C:/Temp/" + row.getValue("NAME") + ".pdf"
arcpy.mapping.ExportToPDF(mxd, somepath)
Let me explain this a little more clearly. In your scenario, you have 2 data frames on a single layout but with different extents. No matter how you address this, you need the equivalent of two index layers; one to drive the first extent, the second to drive the other extent.
Your options:
1) Use DDP to drive the first extent and arcpy.mapping to drive the second extent
or
2) Use arcpy.mapping to drive both extents.
Below is some sample code that sets the 1st data frame's extent based on each feature extent in the first layer:mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] lyr = arcpy.mapping.ListLayers(mxd)[0] rows = arcpy.SearchCursor(lyr.dataSource): for row in rows: newDFExt = row.getValue("Shape").extent df.extent = newDFExtent arcpy.mapping.ExportToPDF(mxd, somepath) del mxd
The logic could be easily extended to multiple data frames.
I hope this helps,
Jeff