GraphicElement
Resumen
The GraphicElement object provides access to properties that enables its repositioning on the page layout.
Debate
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.
Propiedades
Propiedad | Explicación | Tipo de datos |
elementHeight (Lectura y escritura) |
The height of the element in page units. The units assigned or reported are in page units. | Double |
elementPositionX (Lectura y escritura) |
The x location of the data frame element's anchor position. The units assigned or reported are in page units. | Double |
elementPositionY (Lectura y escritura) |
The y location of the data frame element's anchor position. The units assigned or reported are in page units. | Double |
elementWidth (Lectura y escritura) |
The width of the element in page units. The units assigned or reported are in page units. | Double |
name (Lectura y escritura) |
The name of the element. | String |
type (Sólo lectura) |
Returns the element type for any given page layout element.
| String |
Ejemplo de código
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