Exporting Landscape and portrait maps using arpy.datadrivenpages

1126
2
01-20-2013 03:19 AM
DavidMcDermott
New Contributor
Dear GIS community,

I am very much a Python N00b so am in need to your expertise.

Scenario:
I am using data driven pages to export to PDF. Each PDF focuses on a single polygon (in this case a postal zone) along with the relative background map. Of the 18000 polygons, 8000 would best suite a Portrait layout and 10000 would be landscape. The orientation preference is already the the data driven pages index layer. The two mxd's are identical except for their layout.

My Aim:
I am trying to write a python script that would allow me to export a selection of polygons (either by a simple selection or a definition query), using the correct layout. I would be in one of the mxd's when running this script.

So far:
Here is the script I have so far -

# Import arcpy module
import arcpy

#Select Paramaters
Select_Index=arcpy.GetParameterAsText(0)
Select_Portrait_Layout = arcpy.GetParameterAsText(1)
Select_landscape_Layout = arcpy.GetParamterASText(2)
Export_Location = arcpy.GetParamaterAsText(3)

# Local variables:
Input_Feature = Select_Index
Output_Layer = "DDP_Index_Temp"
Select_Portrait_Layout = Select_Portrait_Layout
Select_Index = Select_Index
Select_landscape_Layout = Select_landscape_Layout
Export_Location = Export_Location
mxdport = arcpy.mapping.MapDocument(Select_Portrait_Layout)
mxdland = arcpy.mapping.MapDocument(Select_landscape_Layout)

# Process: Make Feature Layer
arcpy.MakeFeatureLayer_management(Input_Feature, Output_Layer, "", "", "OBJECTID OBJECTID VISIBLE NONE;Shape Shape VISIBLE NONE;NAME NAME VISIBLE NONE;AREA_CODE AREA_CODE VISIBLE NONE;DESCRIPTIO DESCRIPTIO VISIBLE NONE;FILE_NAME FILE_NAME VISIBLE NONE;NUMBER NUMBER VISIBLE NONE;NUMBER0 NUMBER0 VISIBLE NONE;POLYGON_ID POLYGON_ID VISIBLE NONE;UNIT_ID UNIT_ID VISIBLE NONE;CODE CODE VISIBLE NONE;HECTARES HECTARES VISIBLE NONE;AREA AREA VISIBLE NONE;TYPE_CODE TYPE_CODE VISIBLE NONE;DESCRIPT0 DESCRIPT0 VISIBLE NONE;TYPE_COD0 TYPE_COD0 VISIBLE NONE;DESCRIPT1 DESCRIPT1 VISIBLE NONE;Shape_Length Shape_Length VISIBLE NONE;Shape_Area Shape_Area VISIBLE NONE;Orientation Orientation VISIBLE NONE")

# Process: Select Portrait
arcpy.SelectLayerByAttribute_management(Output_Layer, "NEW_SELECTION", "\"Orientation\" = 'PORTRAIT'")

#Process: Export Portrait
mxdport.dataDrivenPages.exportToPDF(Export_Location,'SELECTED')

# Process: Select Landscape
arcpy.SelectLayerByAttribute_management(Output_Layer, "NEW_SELECTION", "\"Orientation\" = 'LANDSCAPE'")

#Process: Export Landscape
mxdland.dataDrivenPages.exportToPDF(Export_Location,'SELECTED')

The issue:
Simply put, it doesn't work. I keep getting the error the following error -
[ATTACH=CONFIG]20891[/ATTACH]

For this I am guessing its that i'm trying to export selected but from the wrong feature....??

help

David McDermott
Tags (2)
0 Kudos
2 Replies
JeffBarrette
Esri Regular Contributor
Have you looked at this facing pages example.  The sample uses two different MXDs similar to what you are trying to do.

http://resources.arcgis.com/en/help/main/10.1/#/Creating_a_map_book_with_facing_pages/00s90000002p00...

Jeff
0 Kudos
DavidMcDermott
New Contributor
Hi Jeff,

I used this example as a template for what I wrote. The difference is I want to select from attributes rather than the page number. The work flow would go as follows:

User
The user selects a group of features from the data driven pages index.

The Script

1. Create a temporary layer of the selection
2. From the temp layer, select [Orientation] = "LANDSCAPE"
3. Export Selected features to multiple PDF [page name] on the Landscape mxd
4. From the temp layer, select [Orientation] = "PORTRAIT"
5. Export Selected features to multiple PDF [page name] on the Portrait mxd
6. Delete temp layer.

I'm not sure of this is a flawed idea as I'm not sure if mapping.datadrivenpages recognizances the temporary feature layer as the input source.
0 Kudos