Attached photo to layout Arcpy?

35 Views Asked by At

I am writing a script to take points from an attribute table and find and replace data in some of my fields into a layout. The text element part is working great but I am struggling to replace the photo slot with the .jpg associated with my data.

att_wlayer = weeds_m.layers[0]

    if att_info:
        for attachment in att_info:
            attachment_id = attachment["id"]

            att_path = att_wlayer.attachments.download(weed_oid, attachment_id)

            for lyt in aprx.listLayouts("Weeds_attachment"):
                for att_elm in lyt.listElements("PICTURE_ELEMENT"):
                    att_elm.sourceImage = att_path

I had a test image that did go away when I ran my script but it was replaced with an empty box instead of the attached image.

I have also thought about exporting the image to my desktop and inserting it to my layout that way, and I would love to see how you could to that if someone thinks that would be easier.

1

There are 1 best solutions below

0
spatialbikejar On BEST ANSWER

If anyone looks at this question and is curious, this is how I downloaded attached photos in ArcGIS Pro, and automated adding them to a layout. This makes sure that if the point being used has an attachment, the associated item is added to a layout.

        attachment_info = att_wlayer.attachments.get_list(oid=object_id)
        
        if attachment_info:
            for attachment in attachment_info:
                attachment_id = attachment["id"]
                attachment_path = att_wlayer.attachments.download(save_path=out_folder)
                print(attachment_path)
                
                for elm in lyt.listElements("PICTURE_ELEMENT"):
                    elm.sourceImage = attachment_path

                weed_att.exportToPDF(os.path.join(exp_path, f"{id}" + '_wa.pdf'))
            
        else:
            print(f"No attachments found for OBJECTID: {object_id}")