ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • Aide
  • Sign Out
ArcGIS Desktop

ArcGIS Online

La plateforme cartographique de votre organisation

ArcGIS Desktop

Un SIG professionnel complet

ArcGIS Enterprise

SIG dans votre entreprise

ArcGIS Developers

Outils de création d'applications de localisation

ArcGIS Solutions

Modèles d'applications et de cartes gratuits pour votre secteur d'activité

ArcGIS Marketplace

Téléchargez des applications et des données pour votre organisation.

  • Documentation
  • Support
Esri
  • Se connecter
user
  • Mon profil
  • Déconnexion

ArcMap

  • Accueil
  • Commencer
  • Carte
  • Analyser
  • Gérer les données
  • Outils
  • Extensions

ApplyLayoutRules

Disponible avec une licence Production Mapping.

  • Résumé
  • Discussion
  • Syntaxe
  • Exemple de code

Résumé

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?

Syntaxe

ApplyLayoutRules (map_document, layout_rules_file)
ParamètreExplicationType de données
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

Exemple de code

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")

ArcGIS Desktop

  • Accueil
  • Documentation
  • Support

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

A propos d'Esri

  • A propos de la société
  • Carrières
  • Blog d’Esri
  • Conférence des utilisateurs
  • Sommet des développeurs
Esri
Donnez-nous votre avis.
Copyright © 2021 Esri. | Confidentialité | Légal