changePageSize
汇总
Layout 对象将引用 ArcGIS Pro 工程 (.aprx) 中的单个页面布局。 可用于访问常见属性(如页面大小)和多个不同的导出方法。
讨论
ArcGIS Pro 工程可包含多个页面布局。 可使用 ArcGISProject 对象上的 listLayouts 方法访问布局,这将返回 Layout 对象的 Python 列表。 有必要确保每个布局均具有唯一名称,因为这样可以通过 name 轻松引用布局。
可以通过 listElements 方法访问页面布局上的所有元素: GraphicElement 、 GroupElement 、 LegendElement 、 MapFrameElement 、 MapSurroundElement 、 PictureElement 、 TableFrameElement 和 TextElement 。
通过 Layout 对象可访问多个 exportTo 方法。 如果想要导出整个页面布局,可使用 Layout 导出方法。 如果只想要导出单个地图框的内容,还可使用 MapFrame 类上的一组相似的导出方法。
布局可以包括单个 MapSeries 。 如果 mapSeries 属性返回 None ,则表明尚未在布局中创建地图系列。 在尝试操作地图系列属性之前,应先检查地图系列是否为 enabled 。
通过 ArcGISProject 对象上的 createLayout 方法,可以完全自动化布局创建过程。 如果存在布局,则有许多其他创建方法可用于创建不同类型的布局元素。 layout 对象具有三种创建方法,可用于创建仅存在于布局中的元素。 包括 createMapFrame 、 createMapSurroundElement 和 createTableFrameElement 。 ArcGISProject 对象包括更多创建方法,允许您在 map 中的布局或图形图层中创建元素。 这些方法包括 createGraphicElement 、 createGroupElement 、 createPictureElement 、 createPredefinedGraphicElement 和 createTextElement 。
openView 方法允许您打开布局的新视图窗格。 由于无法查询视图,目前无法确定视图是否已经打开,或者您的布局视图是否处于活动状态。 您可以使用 ArcGISProject 对象上的 closeViews 方法,并在布局上调用 openView 。 这将打开并激活布局,以使其具有您可能需要的区域和焦点。
注:
openView 和 closeViews 方法仅适用于从应用程序内运行的脚本。 独立脚本无法访问视图窗格。
语法
changePageSize()
属性
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
colorModel (读取和写入) |
返回分配给 |
String |
|
mapSeries (只读) |
如果地图系列存在且已启用,则返回 |
MapSeries |
|
metadata (读取和写入) |
获取或设置布局的 注:设置元数据取决于 |
Metadata |
|
name (读取和写入) |
布局的名称。 建议所有布局都具有唯一的名称,因为这样便可通过这些唯一名称轻松对其进行引用。 |
String |
|
pageHeight (读取和写入) |
布局的页面高度取决于当前的 |
Double |
|
pageUnits (读取和写入) |
布局的页面单位。 下面是设置页面单位时可使用的有效字符串列表。
|
String |
|
pageWidth (读取和写入) |
布局的页面宽度取决于当前的 |
Double |
|
URI (只读) |
布局的统一资源指示符。 这是项目中布局的唯一标识符,使用 Python CIM 访问 时有时需要它。 添加布局并建立 URI 后,该值不会随时间变化。 例如,如果您修改布局的名称,则 |
String |
方法
changePageSize(page_width, page_height, {resize_elements})
changePageSize 方法修改布局的大小。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
page_width |
A double that indicates the width of a layout and is based on the |
Double |
|
page_height |
A double that indicates the height of a layout and is based on the |
Double |
|
resize_elements (可选) |
Specifies whether the elements will be resized. If set to (默认值为 True) |
Boolean |
createBookmarkMapSeries(mapframe, {bookmarks[bookmarks,...]})
此方法为布局创建一个新的 BookmarkMapSeries 。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
mapframe |
A |
MapFrame |
|
bookmarks[bookmarks,...] (可选) |
A list of |
List |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
返回对新的 |
createMapFrame(geometry, {map}, {name})
createMapFrame 方法用于在布局中创建 MapFrame 元素。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
geometry |
The appropriate |
Object |
|
map (可选) |
The (默认值为 None) |
Map |
|
name (可选) |
An optional string that represents the name of the new |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
MapFrame |
如果提供了变量,则其将引用新返回的 |
createMapSurroundElement(geometry, mapsurround_type, {mapframe}, {style_item}, {name})
createMapSurroundElement 方法用于在布局中创建 MapSurroundElement 。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
geometry |
A |
Object |
|
mapsurround_type |
A string that represents the map surround element that will be created
|
String |
|
mapframe (可选) |
The (默认值为 None) |
MapFrame |
|
style_item (可选) |
An optional reference to a |
String |
|
name (可选) |
An optional string that represents the name of the new |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
MapSurroundElement |
返回对新的 |
createSpatialMapSeries(mapframe, index_layer, name_field, {sort_field})
此方法可为布局创建空间 MapSeries object 。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
mapframe |
A |
MapFrame |
|
index_layer |
The index (默认值为 None) |
Layer |
|
name_field |
The field name of the field used to control the name of each page in the map series. Ideally, all field values are unique so each page can be uniquely identified. |
String |
|
sort_field (可选) |
The name of the field that will be used to sort the map series pages. |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
MapSeries |
返回对新的 |
createTableFrameElement(geometry, {mapframe}, {table[table,...]}, {fields}, {style_item}, {name})
createTableFrameElement 方法用于在布局中创建 TableFrameElement 对象。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
geometry |
A |
Object |
|
mapframe (可选) |
The (默认值为 None) |
MapFrame |
|
table[table,...] (可选) |
The (默认值为 None) |
Object |
|
fields (可选) |
A list of strings that represent the table field names to display in the table frame. If the default value of |
String |
|
style_item (可选) |
An optional reference to a |
String |
|
name (可选) |
An optional string that represents the name of the new table frame element. If no name is provided, the default |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
返回对新的 |
deleteElement(element)
deleteElement 函数用于删除布局元素。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
element |
An object that represents a layout element to be deleted. |
Object |
export(export_format, {display_options})
export 方法可使用指定 export_format 导出 Layout 。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
export_format |
The supported export format objects are: |
Object |
|
display_options (可选) |
The |
Object |
exportToAIX(out_aix, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {jpeg_compression_quality}, {embed_fonts}, {embed_color_profile}, {clip_to_elements}, {keep_layout_background}, {convert_markers})
将布局导出为 Adobe Illustrator Exchange (AIX) 格式。 可在 ArcGIS Maps for Adobe Creative Cloud 扩展模块或 Adobe Illustrator 中使用 AIX 文件。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_aix |
用于表示输出导出文件的路径和文件名的字符串。 |
String |
|
resolution (可选) |
用于定义导出文件分辨率的数字,单位为每英寸点数 (dpi)。 (默认值为 300) |
Integer |
|
image_quality (可选) |
用于指定输出图像质量、作为栅格绘制的地图图层的绘制分辨率的字符串。
(默认值为 BEST) |
String |
|
compress_vector_graphics (可选) |
用于控制输出文件的矢量和文本部分压缩的布尔值。 图像压缩单独定义。 (默认值为 True) |
Boolean |
|
image_compression (可选) |
用于指定在输出文件中压缩图像或栅格数据时使用的压缩方案的字符串。
(默认值为 ADAPTIVE) |
String |
|
jpeg_compression_quality (可选) |
当 (默认值为 80) |
Integer |
|
embed_fonts (可选) |
用于控制导出文件中的字体嵌入的布尔值。 当在未安装所需字体的计算机上查看文档时,可通过字体嵌入正确显示文本和字符标记。 (默认值为 True) |
Boolean |
|
embed_color_profile (可选) |
如果设置为 (默认值为 True) |
Boolean |
|
clip_to_elements (可选) |
如果设置为 (默认值为 False) |
Boolean |
|
keep_layout_background (可选) |
如果设置为 (默认值为 False) |
Boolean |
|
convert_markers (可选) |
用于控制将基于字符的标记符号转换为面的布尔值。 如果符号字体不可用或无法嵌入,则可用于正确显示符号。 但是,将此参数设置为 True 将禁用所有基于字符的标记符号的字体嵌入,由此会导致其外观发生变化。 (默认值为 False) |
Boolean |
exportToBMP(out_bmp, {resolution}, {bmp_color_mode}, {bmp_image_compression}, {embed_color_profile}, {clip_to_elements})
将布局导出为 Microsoft Windows 位图格式 (BMP)。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_bmp |
用于表示输出导出文件的路径和文件名的字符串。 |
String |
|
resolution (可选) |
用于定义导出文件分辨率的数字,单位为每英寸点数 (dpi)。 (默认值为 96) |
Integer |
|
bmp_color_mode (可选) |
该值可指定用于描述颜色的位数。
(默认值为 24-BIT_TRUE_COLOR) |
String |
|
bmp_image_compression (可选) |
用于指定在输出文件中压缩图像或栅格数据时使用的压缩方案的字符串。 此选项仅适用于 8 位
(默认值为 NONE) |
String |
|
embed_color_profile (可选) |
如果设置为 (默认值为 True) |
Boolean |
|
clip_to_elements (可选) |
如果设置为 (默认值为 False) |
Boolean |
exportToEMF(out_emf, {resolution}, {image_quality}, {output_as_image}, {clip_to_elements}, {convert_markers})
将布局导出为增强型图元文件 (EMF) 格式。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_emf |
A string that represents the system path and file name for the output export file. |
String |
|
resolution (可选) |
A number that defines the resolution of the export file in dots per inch (dpi). (默认值为 96) |
Integer |
|
image_quality (可选) |
A string that specifies output image quality, the draw resolution of map layers that draw as rasters.
(默认值为 BEST) |
String |
|
output_as_image (可选) |
If set to (默认值为 False) |
Boolean |
|
clip_to_elements (可选) |
If set to (默认值为 False) |
Boolean |
|
convert_markers (可选) |
A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. (默认值为 False) |
Boolean |
exportToEPS(out_eps, {resolution}, {image_compression}, {image_quality}, {embed_fonts}, {output_as_image}, {clip_to_elements}, {convert_markers})
将布局导出为封装 PostScript (EPS) 格式文件。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_eps |
A string that represents the system path and file name for the output export file. |
String |
|
resolution (可选) |
A number that defines the resolution of the export file in dots per inch (dpi). (默认值为 96) |
Integer |
|
image_compression (可选) |
A string that specifies the compression scheme used to compress image or raster data in the output file.
(默认值为 DEFLATE) |
String |
|
image_quality (可选) |
A string that specifies output image quality, the draw resolution of map layers that draw as rasters.
(默认值为 BEST) |
String |
|
embed_fonts (可选) |
A Boolean that controls the embedding of fonts in the export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed. (默认值为 True) |
Boolean |
|
output_as_image (可选) |
If set to (默认值为 False) |
Boolean |
|
clip_to_elements (可选) |
If set to (默认值为 False) |
Boolean |
|
convert_markers (可选) |
A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. (默认值为 False) |
Boolean |
exportToGIF(out_gif, {resolution}, {gif_color_mode}, {clip_to_elements})
将布局导出为图形交换格式 (GIF)。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_gif |
A string that represents the system path and file name for the output export file. |
String |
|
resolution (可选) |
A number that defines the resolution of the export file in dots per inch (dpi). (默认值为 96) |
Integer |
|
gif_color_mode (可选) |
This value specifies the number of bits used to describe color.
(默认值为 8-BIT_ADAPTIVE_PALETTE) |
String |
|
clip_to_elements (可选) |
If set to (默认值为 False) |
Boolean |
exportToJPEG(out_jpg, {resolution}, {jpeg_color_mode}, {jpeg_quality}, {embed_color_profile}, {clip_to_elements})
将布局导出为联合图像专家组 (JPEG) 格式文件。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_jpg |
A string that represents the path and file name of the output export file. |
String |
|
resolution (可选) |
A number that defines the resolution of the export file in dots per inch (dpi). (默认值为 96) |
Integer |
|
jpeg_color_mode (可选) |
This value specifies the number of bits used to describe color.
(默认值为 24-BIT_TRUE_COLOR) |
String |
|
jpeg_quality (可选) |
This value (0–100) controls the amount of compression applied to the output image. With a JPEG image, quality is adversely affected the more compression is applied. A higher quality (highest = 100) setting will produce sharper images and larger file sizes. A lower quality setting will produce more image artifacts and smaller files. (默认值为 80) |
Integer |
|
embed_color_profile (可选) |
If set to (默认值为 True) |
Boolean |
|
clip_to_elements (可选) |
If set to (默认值为 False) |
Boolean |
exportToPAGX(out_pagx)
将布局导出至页面文件 (.pagx)。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_pagx |
A string used to save a layout to a page file ( |
String |
exportToPDF(out_pdf, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, {clip_to_elements}, {output_as_image}, {embed_color_profile}, {pdf_accessibility}, {keep_layout_background}, {convert_markers}, {simulate_overprint})
用于将布局导出为便携文档格式 (PDF)。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_pdf |
A string that represents the path and file name for the output export file. |
String |
|
resolution (可选) |
A number that defines the resolution of the export file in dots per inch (dpi). (默认值为 300) |
Integer |
|
image_quality (可选) |
A string that specifies output image quality, the draw resolution of map layers that draw as rasters.
(默认值为 BEST) |
String |
|
compress_vector_graphics (可选) |
A Boolean that controls compression of vector and text portions of the output file. Image compression is defined separately. (默认值为 True) |
Boolean |
|
image_compression (可选) |
A string that specifies the compression scheme used to compress image or raster data in the output file.
(默认值为 ADAPTIVE) |
String |
|
embed_fonts (可选) |
A Boolean that controls the embedding of fonts in the export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed. (默认值为 True) |
Boolean |
|
layers_attributes (可选) |
A string that specifies whether the PDF layer and PDF object data (attributes) will be included in the export file.
(默认值为 LAYERS_ONLY) |
String |
|
georef_info (可选) |
A Boolean that enables the export of coordinate system information for each data frame into the output PDF file. (默认值为 True) |
Boolean |
|
jpeg_compression_quality (可选) |
A number that controls compression quality value when (默认值为 80) |
Integer |
|
clip_to_elements (可选) |
If set to (默认值为 False) |
Boolean |
|
output_as_image (可选) |
If set to (默认值为 False) |
Boolean |
|
embed_color_profile (可选) |
If set to (默认值为 True) |
Boolean |
|
pdf_accessibility (可选) |
Output a tagged PDF file where text can be read by screen readers or other assistive technology. A tagged PDF file can include alt text—a text description of a graphic element that a screen reader uses to describe the element—for map frames, pictures, and chart frames. Alt text is added in the Element Pane for each element. (默认值为 False) |
Boolean |
|
keep_layout_background (可选) |
If set to True, the white background will be included in the export. (默认值为 True) |
Boolean |
|
convert_markers (可选) |
A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. (默认值为 False) |
Boolean |
|
simulate_overprint (可选) |
Sometimes called soft proofing, simulating overprinting shows a representation of how overlapping areas of ink will appear when printed on a page. You set up overprinting on symbol layers. (默认值为 False) |
Boolean |
exportToPNG(out_png, {resolution}, {color_mode}, {transparent_background}, {embed_color_profile}, {clip_to_elements})
将布局导出为便携式网络图形 (PNG) 格式文件。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_png |
A string that represents the path and file name of the output export file. |
String |
|
resolution (可选) |
A number that defines the resolution of the export file in dots per inch (dpi). (默认值为 96) |
Integer |
|
color_mode (可选) |
This value specifies the number of bits used to describe color.
(默认值为 32-BIT_WITH_ALPHA) |
String |
|
transparent_background (可选) |
If set to (默认值为 False) |
Boolean |
|
embed_color_profile (可选) |
If set to (默认值为 True) |
Boolean |
|
clip_to_elements (可选) |
If set to (默认值为 False) |
Boolean |
exportToSVG(out_svg, {resolution}, {compress_to_svgz}, {image_quality}, {embed_fonts}, {output_as_image}, {clip_to_elements}, {convert_markers})
将布局导出为可伸缩矢量图形 (SVG) 格式。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_svg |
A string that represents the path and file name for the output export file. |
String |
|
resolution (可选) |
A number that defines the resolution of the export file in dots per inch (dpi). (默认值为 96) |
Integer |
|
compress_to_svgz (可选) |
If set to True, the output is compressed. (默认值为 False) |
Boolean |
|
image_quality (可选) |
A string that specifies output image quality, the draw resolution of map layers that draw as rasters.
(默认值为 BEST) |
String |
|
embed_fonts (可选) |
A Boolean that controls the embedding of fonts in the export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed. (默认值为 True) |
Boolean |
|
output_as_image (可选) |
If set to (默认值为 False) |
Boolean |
|
clip_to_elements (可选) |
If set to (默认值为 False) |
Boolean |
|
convert_markers (可选) |
A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. (默认值为 False) |
Boolean |
exportToTGA(out_tga, {resolution}, {color_mode}, {transparent_background}, {clip_to_elements})
将布局导出为 Truevision 图形适配器 (TGA) 格式。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_tga |
A string that represents the path and file name for the output export file. |
String |
|
resolution (可选) |
A number that defines the resolution of the export file in dots per inch (dpi). (默认值为 96) |
Integer |
|
color_mode (可选) |
This value specifies the number of bits used to describe color.
(默认值为 32-BIT_WITH_ALPHA) |
String |
|
transparent_background (可选) |
If set to (默认值为 False) |
Boolean |
|
clip_to_elements (可选) |
If set to (默认值为 False) |
Boolean |
exportToTIFF(out_tif, {resolution}, {color_mode}, {tiff_compression}, {jpeg_compression_quality}, {transparent_background}, {embed_color_profile}, {clip_to_elements}, {world_file}, {geoTIFF_tags}, {georef_mapframe})
将布局导出为标记图像文件格式 (TIFF) 文件。
旧版本:
此方法在 ArcGIS Pro 3.4 中已被
export取代,保留此方法仅供旧版脚本使用。 所有增强功能和未来开发将仅针对导出方法。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
out_tif |
A string that represents the path and file name of the output export file. |
String |
|
resolution (可选) |
A number that defines the resolution of the export file in dots per inch (dpi). (默认值为 96) |
Integer |
|
color_mode (可选) |
This value specifies the number of bits used to describe color. The available options are dependent on the specified Color Model set in the layout's Color Management properties.
(默认值为 24-BIT_TRUE_COLOR) |
String |
|
tiff_compression (可选) |
This value represents a compression scheme.
(默认值为 LZW) |
String |
|
jpeg_compression_quality (可选) |
This value (0–100) controls the amount of compression applied to the output image. With a JPEG image, quality is adversely affected the more compression is applied. A higher-quality (highest = 100) setting will produce sharper images and larger file sizes. A lower-quality setting will produce more image artifacts and smaller files. (默认值为 80) |
Integer |
|
transparent_background (可选) |
If set to (默认值为 False) |
Boolean |
|
embed_color_profile (可选) |
If set to (默认值为 True) |
Boolean |
|
clip_to_elements (可选) |
If set to (默认值为 False) |
Boolean |
|
world_file (可选) |
If set to (默认值为 False) |
Boolean |
|
geoTIFF_tags (可选) |
If set to (默认值为 False) |
Boolean |
|
georef_mapframe (可选) |
The MapFrame used to control the coordinate system when (默认值为 None) |
MapFrame |
getDefinition(cim_version)
获取布局的 CIM 定义。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
cim_version |
A string that represents the major version of the CIM. |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
Object |
返回 |
listElements({element_type}, {wildcard})
返回 Layout 对象包含的页面布局元素的 Python 列表。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
element_type (可选) |
A string that represents the element type that will be used to filter the returned list of elements.
(默认值为 None) |
String |
|
wildcard (可选) |
A wildcard is based on the element name and is not case sensitive. A combination of asterisks (*) and characters can be used to help limit the results. (默认值为 None) |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
List |
页面布局元素的 Python 列表。 可返回的对象类型为 |
openView()
在应用程序中打开并激活一个新的布局视图窗格。
setColorModel(color_model)
用于设置与布局关联的颜色模型的字符串常量。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
color_model |
以下是有效字符串列表。
|
String |
setDefinition(definition_object)
设置布局的 CIM 定义。
| 名称 | 说明 | 数据类型 |
|---|---|---|
|
definition_object |
使用 |
Object |
代码示例
以下脚本遍历当前工程中的所有布局,并打印每个布局的基本信息,包括名称、页面大小和单位、地图框数量、地图框名称以及布局元素的总数。
aprx = arcpy.mp.ArcGISProject('CURRENT')
print(f'Total Project Layout Count: {str(len(aprx.listLayouts()))} \n')
for lyt in aprx.listLayouts():
print(f'Layout Name: {lyt.name}')
print(f' Width x height: {lyt.pageWidth} x {lyt.pageHeight} units are {lyt.pageUnits}')
print(f' MapFrame count: {str(len(lyt.listElements("MapFrame_Element")))}')
for mf in lyt.listElements("MapFrame_Element"):
if len(lyt.listElements("MapFrame_Element")) > 0:
print(f' MapFrame name: {mf.name}')
print(f' Total element count: {str(len(lyt.listElements()))} \n')
以下脚本遍历布局名称列表,并将每个布局导出为 PDF 文件两次。 第一次 export 将使用默认 PDFFormat 设置。 第二次 export 会生成一个小得多的输出文件,因为将相应地在 PDFFormat 对象上设置 resolution 、 image_quality 和 output_as_image 属性。
import arcpy, os
prjPath = r'C:\Projects\YosemiteNP'
p = arcpy.mp.ArcGISProject(os.path.join(prjPath, 'YosemiteTrails.aprx'))
layoutNames = ['Main Attractions', 'Scenic Views']
for lytName in layoutNames:
lyt = p.listLayouts(lytName)[0]
#export to PDF - default settings
pdf = arcpy.mp.CreateExportFormat('PDF', os.path.join(prjPath, 'Output', f'{lytName}_defaults.pdf'))
lyt.export(pdf)
#export to PDF - smaller file size
pdf.filePath = os.path.join(prjPath, 'Output', f'{lytName}_small.pdf')
pdf.setImageQuality("FASTEST")
pdf.outputAsImage = True
pdf.resolution = 72
lyt.export(pdf)
以下脚本创建了一个地图和布局。 它还在布局中创建了一个地图框、指北针和比例尺。 矩形辅助函数用于创建地图框和比例尺所需的几何。 最后,它确保在应用程序中打开并激活新布局。
def MakeRec_LL(llx, lly, w, h):
xyRecList = [[llx, lly], [llx, lly+h], [llx+w,lly+h], [llx+w,lly], [llx,lly]]
array = arcpy.Array([arcpy.Point(*coords) for coords in xyRecList])
rec = arcpy.Polygon(array)
return rec
p = arcpy.mp.ArcGISProject('current')
#Create a new map and layout
m = p.createMap('New Map', 'MAP')
lyt = p.createLayout(8.5, 11, 'INCH')
#Create a map frame
mf = lyt.createMapFrame(MakeRec_LL(0.5,5.5,7.5,5), m, "New Map Frame")
#Create a north arrow
naStyle = p.listStyleItems('ArcGIS 2D', 'North_Arrow', 'Compass North 1')[0]
na = lyt.createMapSurroundElement(arcpy.Point(7,7), 'North_Arrow', mf,
naStyle, "Compass North Arrow")
na.elementWidth = 0.5
#Create a scale bar
sbName = 'Double Alternating Scale Bar 1 Metric'
sbStyle = p.listStyleItems('ArcGIS 2D', 'Scale_bar', sbName)[0]
sbEnv = MakeRec_LL(0.5, 5.5, 2.5, 0.5)
sb = lyt.createMapSurroundElement(sbEnv, 'Scale_bar', mf, sbStyle, 'New Scale Bar')
#Close all view and open and active the layout view
p.closeViews()
lyt.openView()
以下脚本展示了使用 deleteElement 的不同方式。 请注意,要移除可能存在于其他组元素内部的组元素,必须以相反的顺序删除组元素,因为在删除父元素之前,必须先删除子元素。
p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Layout')[0]
#Delete one element by name
elm = lyt.listElements('GRAPHIC_ELEMENT', 'Point')[0]
lyt.deleteElement(elm)
#Delete all the group elements and their children in reverse order
for elm in reversed(lyt.listElements('GROUP_ELEMENT')):
lyt.deleteElement(elm)
#Delete remaining elements
for elm in lyt.listElements():
lyt.deleteElement(elm)
以下脚本演示了如何使用 Python CIM 访问 向布局添加参考线。 它在布局中创建了四条距离布局边缘 0.5 英寸的新参考线。
#CAUTION - this script will remove any existing guides
p = arcpy.mp.ArcGISProject('CURRENT')
for lyt in p.listLayouts():
lyt_cim = lyt.getDefinition('V3')
newGuides = []
#Bottom horizontal guide
botHorz = arcpy.cim.CreateCIMObjectFromClassName('CIMGuide', 'V3')
botHorz.position = 0.5
botHorz.orientation = 'Horizontal'
newGuides.append(botHorz)
#Top horizontal guide
topHorz = arcpy.cim.CreateCIMObjectFromClassName('CIMGuide', 'V3')
topHorz.position = lyt.pageHeight - 0.5
topHorz.orientation = 'Horizontal'
newGuides.append(topHorz)
#Left vertical guide
leftVert = arcpy.cim.CreateCIMObjectFromClassName('CIMGuide', 'V3')
leftVert.position = 0.5
leftVert.orientation = 'Vertical'
newGuides.append(leftVert)
#Right vertical guide
rightVert = arcpy.cim.CreateCIMObjectFromClassName('CIMGuide', 'V3')
rightVert.position = lyt.pageWidth - 0.5
rightVert.orientation = 'Vertical'
newGuides.append(rightVert)
#Add guides and make sure they are turned on
lyt_cim.page.guides = newGuides
lyt_cim.page.showGuides = True
#Set back to layer
lyt.setDefinition(lyt_cim)