Skip to main content

applyStyleItem

汇总

TableFrameElement 类提供对功能的访问,允许您修改表格信息在 Layout 类上的显示方式。

讨论

表格框元素是一种专门的地图整饰要素,它具有关联的 MapFrame 元素,并且还动态链接到 图层 对象以显示其行和字段。 listElements 类上的 Layout 方法将返回包含所有可能布局元素的 Python 列表。 要仅返回 TableFrameElement 对象的列表,应对 TABLEFRAME_ELEMENT 参数使用 element_type 常量。 还可以使用 wildcard 值,基于元素的 name 值对搜索进行进一步优化。 有必要确保为每个布局元素指定唯一名称,因为这样可以在 ArcPy 脚本中引用它。

Layout 类的 createTableFrameElement 方法可用的所有参数也都在 TableFrameElement 类上公开,例如 mapframetablefields - 可以对现有表格框进行更改。 您可以使用许多属性来调整表格框的大小和位置。 您还可以使用 sortFields 方法修改表格框的外观,或使用 setQuery 方法控制表中显示的行。 表格框元素还具有可用于修改未向 getDefinition 类公开的其他属性的 setDefinitionTableFrameElement 方法。 有关详细信息,请参阅下面的示例和 Python CIM 访问 帮助主题。

语法

applyStyleItem()

属性

名称 说明 数据类型

anchor

(只读)

返回表示当前锚点位置的以下字符串值之一。 要更改值,请使用 setAnchor 方法。

  • BOTTOM_LEFT_CORNER—左下角位置

  • BOTTOM_MID_POINT—底部中央位置

  • BOTTOM_RIGHT_CORNER—右下角位置

  • CENTER_POINT—中央位置

  • LEFT_MID_POINT—左侧中央位置

  • RIGHT_MID_POINT—右侧中央位置

  • TOP_LEFT_CORNER—左上角位置

  • TOP_MID_POINT—顶部中央位置

  • TOP_RIGHT_CORNER—右上角位置

String

elementHeight

(读取和写入)

元素的高度(以页面单位计)。

Double

elementPositionX

(读取和写入)

元素的锚点位置的 x 位置。 分配或报告的单位为页面单位。

Double

elementPositionY

(读取和写入)

元素的锚点位置的 y 位置。 分配或报告的单位为页面单位。

Double

elementWidth

(读取和写入)

元素的宽度(以页面单位计)。

Double

fields

(读取和写入)

表示表格框中显示的表字段名称的字符串列表。

List

isOverflowing

(只读)

如果表格框中的所有内容均不在所提供几何的边界内,则返回 True 。 这种情况下,布局上通常会显示红色省略号。 该属性在 while 循环的上下文中效果很好。 它可以支持更改字体大小或元素大小,直到所有内容均能容纳。

Boolean

locked

(读取和写入)

设置为 True 时,无法在布局视图中以图形方式选择元素。

Boolean

longName

(只读)

元素的全名,包括组信息(如果存在)。 例如,在一个名称为 Table Frame 的组元素中,名称为 Group Element 的元素将返回 longNameGroup Element\\Table Frame 值。 如果元素不在组中,则 longNamename 值相同。

String

mapFrame

(读取和写入)

对关联 MapFrame 的引用。

MapFrame

name

(读取和写入)

元素的名称。 必须确保所有元素均具有唯一名称,因为这样可以通过在 Layout 对象的 listElements 函数中使用 wildcard 参数以唯一方式引用这些元素。

String

parentGroupElement

(只读)

如果元素在组中,则返回的值为 GroupElement ,否则返回 NoneType

GroupElement

query

(只读)

返回以下字符串值之一,这些值表示控制应显示哪些行的当前查询。 要更改值,请使用 setQuery 方法。

  • ALL_ROWS—显示表中所有行。

  • MAPSERIES_ROWS—如果启用了空间地图系列,则显示与当前索引要素关联的行。

  • VISIBLE_ROWS—仅显示地图框中的可见要素。

String

table

(读取和写入)

与表格框关联的 LayerTable 对象。

Object

type

(只读)

返回值 TABLEFRAME_ELEMENT

String

visible

(读取和写入)

如果元素在布局上可见,则返回 True

Boolean

方法

applyStyleItem(style_item)

StyleItem 应用于 TableFrameElement

名称 说明 数据类型

style_item

A reference to a StyleItem in a project.

StyleItem

getDefinition(cim_version)

返回表格框元素的 CIM 定义。

名称 说明 数据类型

cim_version

A string that represents the major version of the CIM that will be used.

  • V2—The 2.x version of the CIM will be used.

  • V3—The 3.x version of the CIM will be used.

String

返回值

数据类型 说明

Object

返回 TableFrameElement 值的 CIM 定义。

setAnchor(anchor)

setAnchor 方法可控制 TableFrameElement 值的锚点位置。

名称 说明 数据类型

anchor

A string that specifies the location of the anchor position.

  • BOTTOM_LEFT_CORNER—The anchor will be set at the bottom left corner position.

  • BOTTOM_MID_POINT—The anchor will be set at the bottom center position.

  • BOTTOM_RIGHT_CORNER—The anchor will be set at the bottom right corner position.

  • CENTER_POINT—The anchor will be set at the center position.

  • LEFT_MID_POINT—The anchor will be set at the left center position.

  • RIGHT_MID_POINT—The anchor will be set at the right center position.

  • TOP_LEFT_CORNER—The anchor will be set at the top left corner position.

  • TOP_MID_POINT—The anchor will be set at the top center position.

  • TOP_RIGHT_CORNER—The anchor will be set at the top right corner position.

String

setDefinition(definition_object)

setDefinition 方法设置表格框元素的 CIM 定义。

名称 说明 数据类型

definition_object

A modified CIM definition object originally retrieved using getDefinition.

Object

setQuery(query_rows)

setQuery 方法控制表格框中的行显示。

名称 说明 数据类型

query_rows

A keyword string that serves as a filter and specifies the rows that will be displayed in the table frame.

  • ALL_ROWS—All rows in the table will be displayed.

  • MAPSERIES_ROWS—The row associated with the current index feature will be displayed if a spatial map series is enabled.

  • VISIBLE_ROWS—Only the visible features in the map frame will be displayed.

(默认值为 ALL_ROWS)

String

sortFields(field_info[field_info,...])

sortFields 方法使用一个或多个字段的字典键值对的列表对表格框进行排序。

名称 说明 数据类型

field_info[field_info,...]

A list of Python dictionaries that each contain field sorting information. The dictionary keys are defined below.

  • name—A string that represents the name of the field used to sort.

  • ascending—A Boolean value of True will sort in ascending order. The default value is True.

  • caseSensitive—A Boolean value of True will honor case while sorting. The default value is True.

List

代码示例

TableFrameElement 示例 1

以下脚本在布局中创建了表格框。 它使用函数来构造用于将表格框放置在布局上的包络矩形。

def MakeRec_UL(ulx, uly, w, h):
    xyRecList = [[ulx, uly], [ulx+w, uly], [ulx+w,uly-h], [ulx,uly-h], [ulx,uly]]
    array = arcpy.Array([arcpy.Point(*coords) for coords in xyRecList])
    rect = arcpy.Polygon(array)
    return rect

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Map')[0]
lyr = m.listLayers('States*')[0]
lyt = p.listLayouts('Create*')[0]
mf = lyt.listElements()[0]

#States table frame
tfStyle = p.listStyleItems('ArcGIS 2D', 'TABLE_FRAME', 'Blue Alternating Rows')[0]
tfEnv = MakeRec_UL(0.5, 5, 7.5, 4)
tfFields = ['STATE_NAME', 'STATE_ABBR', 'POP2000', 'POP2010']
tf = lyt.createTableFrameElement(tfEnv, mf, lyr, tfFields, tfStyle, 'States TableFrame')

#Display only visible rows
tf.setQuery('VISIBLE_ROWS')
TableFrameElement 示例 2

以下脚本引用现有表格框并使用类方法修改其外观。 脚本对通过 Python CIM 访问公开的属性进行其他更改。

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Modify*')[0]
tf = lyt.listElements('TABLEFRAME_ELEMENT', 'States*')[0]

#Modify table frame
tf.setQuery('VISIBLE_ROWS')
tf.sort({'name':'STATE_NAME', 'ascending':True, 'caseSensitive':True})

#Modify additional properties using the CIM
tf_cim = tf.getDefinition('V3')
tf_cim.minFontSize = 8
tf_cim.alternate1RowBackgroundCount = 2
tf_cim.alternate2RowBackgroundCount = 2
tf_cim.balanceColumns = False
tf_cim.columnGap = 75
tf_cim.fittingStrategy = 'AdjustColumnsAndSize'
tf.setDefinition(tf_cim)
TableFrameElement 示例 3

以下脚本在创建新的表格框之前创建空间地图系列。 它通过将 query 值设置为 MAPSERIES_ROWS 来完成。

def MakeRec_UL(ulx, uly, w, h):
    xyRecList = [[ulx, uly], [ulx+w, uly], [ulx+w,uly-h], [ulx,uly-h], [ulx,uly]]
    array = arcpy.Array([arcpy.Point(*coords) for coords in xyRecList])
    rect = arcpy.Polygon(array)
    return rect

p = arcpy.mp.ArcGISProject('current')
m = p.listMaps('Map')[0]
lyr = m.listLayers('GreatLakes')[0]
lyt = p.listLayouts('MapSeries')[0]
mf = lyt.listElements()[0]

#Create a spatial map series
lyt.createSpatialMapSeries(mf, lyr, 'NAME', 'AREA')

#Create a table frame
tfStyle = p.listStyleItems('ArcGIS 2D', 'TABLE_FRAME', 'Orange Alternating Rows')[0]
tfEnv = MakeRec_UL(0.5, 5.75, 7.5, 2)
tf = lyt.createTableFrameElement(tfEnv, mf, lyr, ['NAME', 'AREA'], tfStyle, 'Great Lakes TableFrame')

#Set the query to match mapseries rows
tf.setQuery('MAPSERIES_ROWS')