Available with Production Mapping license.
Summary
Applies layout rules to a map document to adjust page size and position of surround elements.
Discussion
Layout rules allow you to define the relative placement of surround elements on the page layout and dynamically adjust your page sizes. You can create placement rules that will maintain consistent placement across all map documents. You can create placement rules for any surround element.
Layout rules can be configured using the Layout window in ArcMap. You can then automate the layout position of elements on a map-making application using the ApplyLayoutRules function. The function also supports Data Driven Pages-enabled MXDs. In Data Driven Pages, it allows you to control the layout when you switch from page to page and the position of elements change, such as titles or legends.
For more information, see What are layout rules?
Syntax
ApplyLayoutRules (map_document, layout_rules_file)
Parameter | Explanation | Data Type |
map_document | A variable that references a MapDocument object. | MapDocument |
layout_rules_file | A path to a file that contains the layout rule settings. | String |
Code sample
ApplyLayoutRules example 1
This script shows how layout rules can be applied to a single MXD.
import arcpy
import arcpyproduction
# Check out Production Mapping extension
arcpy.CheckOutExtension("foundation")
# Define variables
mxd = arcpy.mapping.MapDocument('CURRENT')
rules = r"C:\Project\LayoutRules.xml"
# Apply the Layout Rules from LayoutRules.xml
arcpyproduction.mapping.ApplyLayoutRules(mxd, rules)
# Check in Production Mapping extension
arcpy.CheckInExtension("foundation")
ApplyLayoutRules example 2
This script shows how layout rules can be applied to Data Driven Pages. You can move from page to page and layout rules are applied to ensure layout elements don’t overlap.
import arcpy
import arcpyproduction
import os
# Check out Production Mapping extension
arcpy.CheckOutExtension("foundation")
# Define variables
mxd = arcpy.mapping.MapDocument(r'C:\Project\CountiesDDP.mxd')
mxdddp = mxd.dataDrivenPages
rules = r"C:\Project\LayoutRules.xml"
# Process each page in the map document and apply layout rules
for page in range(1, mxdddp.pageCount+1):
mxdddp.currentPageID = page
ddp_row = mxdddp.pageRow
ddp_field = mxdddp.pageNameField
val = ddp_row.getValue(ddp_field.name)
arcpyproduction.mapping.ApplyLayoutRules(mxd, rules)
# Apply a definition query to see only the features of interest
lyr_list = arcpy.mapping.ListLayers(mxd)
for lyr in lyr_list:
if lyr.name.find("Counties") > -1:
lyr.definitionQuery = "NAME = '"+val+"'"
# Export to PDF
outpdf = r"C:\Project\PDF"+os.sep+str(mxdddp.currentPageID)+"page.pdf"
mxdddp.exportToPDF(outpdf,"CURRENT")
print "Exported " + outpdf
# Reset the definition query
for lyr in lyr_list:
if lyr.name.find("Counties") > -1:
lyr.definitionQuery = ""
# Check in Production Mapping extension
arcpy.CheckInExtension("foundation")