I was wondering if there was a way to put a title and integer data from an attribute table in a new layer created in Python. I was able to create a new layer using copy features, zoom to the selected features, and export the zoomed features in a map as a PNG all using arcpy, but I also wanted a title at the top and data from the attribute table of that specific layer in the map layout before it was exported. Is it possible to get all this automated using Python?
Yes, just do a search cursor to get the specific field/record value and update layout default title text (you set this within a template map document), see sample code below.
import arcpy # run search cursor here mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"): if elm.text == "default title text": elm.text = myFieldValue # variable grabed from search cursor mxd.save() del mxd
If you want to export the map layout to png you may use ExportToPNG