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?
1 Answer
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
-
Would I be able to do this from a new layer in the same arcpy process? I created a new feature layer and I wanted that layer to be edited with title and density data from the attribute table and then exported to PNG all within the same script. Is that possible with the search cursor?– VictorCommented Dec 12, 2013 at 20:50
-
@Victor, Yes it should be possible. If you post your script within your question I may be able to further assist. Commented Dec 13, 2013 at 13:09