GroupElement

Synthèse

The GroupElement object provides access to properties for group elements in a layout.

Discussion

The listElements method on the Layout object returns a Python list of layout elements. To return a list of only GroupElement objects, use the GROUP_ELEMENT constant for the element_type parameter. A wildcard value can also be used to further refine the search based on the element's name value. It is important that each element be given a unique name so that it can be easily referenced.

Group elements can be created using the createGroupElement method on the ArcGISProject class. To create a group element, elements must exist and be added to the required element_list parameter. In other words, you cannot create an empty group element. You can create group elements inside other existing group elements.

The GroupElement object is important for many of the map graphic and layout element creation methods. Like the GroupElement object, many of the other methods have a destination container parameter, and if the value is a group element, the newly created objects will be added to the specified group element. The container parameter can be a graphics layer in a map, a Layout, or a reference to an existing GroupElement object in a layout.

Remarque :

You can only group elements that are at the same level in the Contents pane. For example, you can group a graphic element, a group element, and a map surround element all positioned at the root of the Contents pane into a new group but you cannot group a graphic element at the root level and another graphic element in a group.

The deleteElement method on the Layout class allows you to delete elements in a layout. To remove group elements that may exist inside other group elements, you must delete group elements in opposite order because you must delete the child groups before the parent group. See the second code example below.

Remarque :

Prior to version 3.2, group elements in a layout were categorized as a GraphicElement and would return a type value of GRAPHIC_ELEMENT. To maintain compatibility with older scripts, the isGroup property was carried over from the GraphicElement object. It is not necessary to use this property with newer scripts because a group element now has a type value of GROUP_ELEMENT and can be searched and referenced using the Layout listElements method with the value of GROUP_ELEMENT for the element_type pick list.

Propriétés

PropriétéExplicationType de données
anchor
(Lecture seule)

Returns one of the following string values that represent the current anchor position. To change the value, use the setAnchor method.

  • BOTTOM_LEFT_CORNERBottom left corner position
  • BOTTOM_MID_POINTBottom center position
  • BOTTOM_RIGHT_CORNERBottom right corner position
  • CENTER_POINTCenter position
  • LEFT_MID_POINTLeft center position
  • RIGHT_MID_POINTRight center position
  • TOP_LEFT_CORNERTop left corner position
  • TOP_MID_POINTTop center position
  • TOP_RIGHT_CORNERTop right corner position
String
elementHeight
(Lecture et écriture)

The height of the element in either layout page units or map units.

Double
elementPositionX
(Lecture et écriture)

The x-location of the element's anchor position in either layout page units or map units.

Double
elementPositionY
(Lecture et écriture)

The y-location of the element's anchor position in either layout page units or map units.

Double
elementRotation
(Lecture et écriture)

The element's rotation angle in degrees. Positive values rotate clockwise and negative values rotate counterclockwise.

Double
elements
(Lecture seule)

Returns a list of elements in the GroupElement object.

List
elementWidth
(Lecture et écriture)

The width of the element in either layout page units or map units.

Double
isGroup
(Lecture seule)

Returns True if the element is a GroupElement. Refer to the discussion for additional information.

Boolean
locked
(Lecture et écriture)

When set to True, the element cannot be graphically selected in the layout view.

Boolean
longName
(Lecture seule)

An element's full name including group information if it exists. For example, an element named 'Point' in a group element named 'Group Element' will return a longName value of 'Group Element\\Point'. If the element is not in a group, the longName will be the same as the name value.

String
name
(Lecture et écriture)

The name of the element. It is important that all elements have a unique name so they can be easily referenced.

String
parentGroupElement
(Lecture seule)

If an element, including a GroupElement, is in a group, the value returned will be a GroupElement, otherwise a NoneType will be returned.

GroupElement
type
(Lecture seule)

Returns a value of GROUP_ELEMENT.

String
visible
(Lecture et écriture)

Returns True if the element is visible.

Boolean

Vue d’ensemble des méthodes

MéthodeExplication
getDefinition (cim_version)

Returns a graphic element's CIM definition.

setAnchor (anchor)

The setAnchor method controls the anchor position for a GroupElement value.

setDefinition (definition_object)

Sets a group element's CIM definition.

ungroupElements ()

The ungroupElements method separates all elements in the group element.

Méthodes

getDefinition (cim_version)
ParamètreExplicationType de données
cim_version

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

  • V2The 2.x version of the CIM will be used.
  • V3The 3.x version of the CIM will be used.
String
Valeur renvoyée
Type de donnéesExplication
Object

Returns the CIM definition for a GraphicElement.

For more information about working with the CIM and samples, see Python CIM access.

setAnchor (anchor)
ParamètreExplicationType de données
anchor

A string that specifies the location of the anchor position.

  • BOTTOM_LEFT_CORNERThe anchor will be set at the bottom left corner position.
  • BOTTOM_MID_POINTThe anchor will be set at the bottom center position.
  • BOTTOM_RIGHT_CORNERThe anchor will be set at the bottom right corner position.
  • CENTER_POINTThe anchor will be set at the center position.
  • LEFT_MID_POINTThe anchor will be set at the left center position.
  • RIGHT_MID_POINTThe anchor will be set at the right center position.
  • TOP_LEFT_CORNERThe anchor will be set at the top left corner position.
  • TOP_MID_POINTThe anchor will be set at the top center position.
  • TOP_RIGHT_CORNERThe anchor will be set at the top right corner position.
String

Setting the anchor position is helpful because you can control how the element might expand when resized. For example, the default anchor position for a group element is BOTTOM_LEFT_CORNER. If you change the anchor location to TOP_RIGHT_CORNER, changing elementHeight will expand the element downward instead of upward (the default), and changing elementWidth will expand the element to the left.

setDefinition (definition_object)
ParamètreExplicationType de données
definition_object

A modified CIM definition object originally retrieved using getDefinition.

Object

For more information about working with the CIM and samples, see Python CIM access.

ungroupElements ()

The elements are separated into the parentGroup value of the GroupElement value and the group element is removed. If no parent group exists, the elements are placed at the root level of the layout.

Exemple de code

GroupElement example 1

The following script groups all GraphicElement objects into one group and all TextElement objects into a second group. Then both resulting group elements are grouped into a third, parent group. At the start of the script, all elements are at the root level of the Contents pane.

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 example 2

The following script deletes all elements on a layout. If group elements exist inside other group elements, is important to remove group elements in reverse order because the child groups need to be removed before the parent groups.

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)