ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

ApplyLayoutRules

获得 Production Mapping 许可后可用。

  • 描述
  • 讨论
  • 语法
  • 代码示例

描述

Applies layout rules to a map document to adjust page size and position of surround elements.

讨论

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?

语法

ApplyLayoutRules (map_document, layout_rules_file)
参数说明数据类型
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

代码示例

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

  • 主页
  • 文档
  • 支持

ArcGIS

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

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2021 Esri. | 隐私政策 | 法律声明