Skip to main content

getDefinition

汇总

GroupElement 对象提供了对 布局 中组元素属性的访问。

讨论

Layout 对象上的 listElements 方法将返回布局元素的 Python 列表。 要仅返回 GroupElement 对象的列表,应对 element_type 参数使用 GROUP_ELEMENT 常量。 还可以使用 wildcard 值,基于元素的 name 值对搜索进行进一步优化。 需要确保每个元素均具有唯一名称,以便轻松对其进行引用。

可以使用 ArcGISProject 类上的 createGroupElement 方法创建组元素。 要创建组元素,元素必须存在并将其添加至所需 element_list 参数。 即,无法创建空的组元素。 可以在其他现有组元素内创建组元素。

GroupElement 对象对于许多地图图形和布局元素创建方法都非常重要。 与 GroupElement 对象一样,许多其他方法都具有目标 container 参数,如果该值为组元素,则会将新创建的对象添加至指定组元素。 container 参数可以是地图中的图形图层、 Layout 或者对布局中现有 GroupElement 对象的引用。

注:

只能对 内容 窗格中同一级别的元素进行分组。 例如,可以将位于 内容 窗格根部的图形元素、组元素和地图整饰要素元素分组到一个新组中,但无法对根级别的图形元素以及组中的另一个图形元素进行分组。

Layout 类上的 deleteElement 方法用于删除布局中的元素。 要移除可能存在于其他组元素内部的组元素,必须以相反的顺序删除组元素,因为在删除父组之前,必须先删除子组。 请参阅以下第二个代码示例。

注:

在低于 3.2 的版本中,布局中的组元素被归类为 GraphicElement 并将返回 GRAPHIC_ELEMENTtype 值。 为了保持与旧脚本的兼容性, isGroup 属性是从 GraphicElement 对象继承的。 无需将此属性与较新的脚本配合使用,因为组元素现在的 type 值为 GROUP_ELEMENT ,并且可以使用 Layout listElements 方法以及 element_type 选择列表的 GROUP_ELEMENT 值对其进行搜索和引用。

语法

getDefinition()

属性

名称 说明 数据类型

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

elementRotation

(读取和写入)

元素旋转角度(以度为单位)。 正值将使方向顺时针旋转,负值将使方向逆时针旋转。

Double

elements

(只读)

返回 GroupElement 对象中的元素列表。

List

elementWidth

(读取和写入)

采用布局页面单位或地图单位的元素宽度。

Double

isGroup

(只读)

如果元素是 GroupElement ,则返回 True 。 请参阅讨论以获取其他信息。

Boolean

locked

(读取和写入)

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

Boolean

longName

(只读)

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

String

name

(读取和写入)

元素的名称。 有必要确保所有元素均具有唯一名称,因为这样可以轻松对其进行引用。

String

parentGroupElement

(只读)

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

GroupElement

type

(只读)

返回值 GROUP_ELEMENT

String

visible

(读取和写入)

如果元素可见,则返回 True

Boolean

方法

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

返回 GraphicElement 的 CIM 定义。

setAnchor(anchor)

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

名称 说明 数据类型

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)

设置群组元素的 CIM 定义。

名称 说明 数据类型

definition_object

A modified CIM definition object originally retrieved using getDefinition.

Object

ungroupElements()

ungroupElements 方法可在群组元素中分隔元素。

代码示例

GroupElement 示例 1

以下脚本将所有 GraphicElement 对象分组为第一组,将所有 TextElement 对象分组为第二组。 然后,将两个结果组元素分组到第三个父组中。 在脚本开头,所有元素均位于 内容 窗格的根级别。

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Layout')[0]

#Group graphic elements
graElmList = []
for gra in lyt.listElements('GRAPHIC_ELEMENT'):
  graElmList.append(gra)
graphics = p.createGroupElement(lyt, graElmList, 'Graphic Elements')

#Group text elements
txtElmList = []
for txt in lyt.listElements('TEXT_ELEMENT'):
  txtElmList.append(txt)
text = p.createGroupElement(lyt, txtElmList, 'Text Elements')

#Group of groups
supGrp = p.createGroupElement(lyt, [graphics, text], 'Group of Groups')
GroupElement 示例 2

以下脚本用于删除布局上的所有元素。 如果组元素存在于其他组元素内部,则必须以相反的顺序移除组元素,因为在移除父组之前,需要先移除子组。

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Layout')[0]

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