0

I have 1500 MXDs with the same template layout, and need to insert other images for the all MXDs, can I do this using Python?

I'm using ArcGIS 10.1

  • 1
    Do you already have the picture element in the layout or do you want to add a new picture element.It's not possible to add a new layout element with arcpy. – landocalrissian Jun 11 '15 at 16:14
  • i have one picture element in layout , ist posible copy that element picture? – Camilo A Garcia Jun 11 '15 at 16:22
  • It is possible to clone a text or graphic element but I don't think you can with a picture element but I could be wrong. – landocalrissian Jun 11 '15 at 16:27
2

If you just want to change the source of an existing picture element there is a code snippet in the ArcGIS help.You would of course have to know the name of your picture element.

The following script will find an image by name and set its data source to a new location.

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
for elm in arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT"):
    if elm.name == "Photo":
        elm.sourceImage = r"C:\Project\Data\NewPhoto.bmp"
mxd.save()
del mxd

The following script demonstrates how different pictures can be switched out for each page in a Data Driven Pages enabled map document. There is a different picture for each page. The pictures are named Photo1.png, Photo2.png, Photo3.png, etc to match the corresponding page numbers.

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
pict = arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT", "photo")[0]
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    pict.sourceImage = r"C:\Project\Data\Photo{0}.png".format(pageNum)
    print("Exporting page {0} of {1}"
          .format(mxd.dataDrivenPages.currentPageID,
                  mxd.dataDrivenPages.pageCount))
    arcpy.mapping.ExportToPDF(mxd, r"C:\Project\Page{0}.pdf".format(pageNum))
del mxd
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.