GraphicElement

Récapitulatif

The GraphicElement object provides access to properties that enables its repositioning on the page layout.

Discussion

The GraphicElement is a catch-all element type for most generic elements added to a page layout. It includes items such as groups of elements, inserted tables, graphs, neatlines, markers, lines, area shapes, and so on, that are added to a page layout. The most common operations on a graphic element are to get or set its page layout position and size. The ListLayoutElements function returns a Python list of page layout element objects. It is necessary to then iterate through each item in the list or specify an index number to reference a specific page element object.

To return a list of only GraphicElements, use the GRAPHIC_ELEMENT constant for the element_type parameter. A wildcard can also be used to further refine the search based on the element name.

ListLayoutElements will return a flattened list of elements. For example, ListLayoutElements on a graphic element that represents a group of three text elements will return a total of four elements: the group element and each individual text element. The GraphicElement can be used to reposition all items at the same time or the text element text values can be managed individually.

It is recommended that each page layout element be given a unique name so that it can be easily isolated using arcpy scripting. This is set via the Size and Position Tab on the Properties dialog box in ArcMap.

X and Y element positions are based on the element's anchor position which is also set via the Size and Position tab on the Properties dialog box in ArcMap.

Page units can only be changed in ArcMap via Customize > ArcMap Options > Layout View Tab.

Propriétés

PropriétéExplicationType de données
elementHeight
(Lecture et écriture)

The height of the element in page units. The units assigned or reported are in page units.

Double
elementPositionX
(Lecture et écriture)

The x location of the data frame element's anchor position. The units assigned or reported are in page units.

Double
elementPositionY
(Lecture et écriture)

The y location of the data frame element's anchor position. The units assigned or reported are in page units.

Double
elementWidth
(Lecture et écriture)

The width of the element in page units. The units assigned or reported are in page units.

Double
name
(Lecture et écriture)

The name of the element.

String
type
(Lecture seule)

Returns the element type for any given page layout element.

  • DATAFRAME_ELEMENTData frame element
  • GRAPHIC_ELEMENTGraphic element
  • LEGEND_ELEMENTLegend element
  • MAPSURROUND_ELEMENTMap surround element
  • PICTURE_ELEMENTPicture element
  • TEXT_ELEMENTText element
String

Exemple de code

GraphicElement example:

The following script will move a group element named Title Block to a new location on the page layout and then save the changes.

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
for elm in arcpy.mapping.ListLayoutElements(mxd, "GRAPHIC_ELEMENT"):
    if elm.name == "Title Block":
        elm.elementPositionX = 4.75
        elm.elementPositionY = 10.5
mxd.save()
del mxd

7/10/2012