Resumen
Provides access to properties that enables its repositioning on the page layout as well as identifying its associated map frame.
Debate
A MapsurroundElement object is a page element that has an association with a MapFrame object using a property named mapFrame. The listElements method on the Layout object 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 MapsurroundElements only, use the MAPSURROUND_ELEMENT constant for the element_type parameter. A wildcard can also be used to further refine the search based on the element name. It is important that each page layout element be given a unique name so that it can be easily isolated using ArcPy scripting.
The elementPositionX and elementPositionY values are based on the element's anchor position, which is set on the Format tab.
Propiedades
Propiedad | Explicación | Tipo de datos |
elementHeight (Lectura y escritura) | The height of the element in page units. | Double |
elementPositionX (Lectura y escritura) | The x-location of the element's anchor position. The units assigned or reported are in page units. | Double |
elementPositionY (Lectura y escritura) | The y-location of the 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. | Double |
locked (Lectura y escritura) | When set to True, the element cannot be graphically selected in the layout view. | Boolean |
mapFrame (Lectura y escritura) | A reference to the associated MapFrame. | MapFrame |
name (Lectura y escritura) | The name of the element. It is important that all elements have a unique name so they can be easily referenced. | String |
type (Sólo lectura) | Returns a value of MAPSURROUND_ELEMENT. | String |
visible (Lectura y escritura) | Returns True if the element is visible on the layout. Rather than having to move unwanted objects off the page before printing or exporting, you can turn the element's visibility on and off. | Boolean |
Muestra de código
The following script will find the MapsurroundElement named ScaleBar and change its position so the center of the scale bar is located 0.5 page units below and to the center of its associated map frame. Note that the scale bar was authored with its anchor location in the center position. The map frame was authored with its an anchor position located to the lower left.
import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\Projects\YosemiteNP\Yosemite.aprx")
lyt = aprx.listLayouts("Points of Interest")[0]
scaleBar = lyt.listElements("MAPSURROUND_ELEMENT", "ScaleBar")[0]
mf = scaleBar.mapFrame
scaleBar.elementPositionX = mf.elementPositionX + (mf.elementWidth / 2)
scaleBar.elementPositionY = mf.elementPositionY - 0.5
aprx.save()
del aprx