Python Picture_Element Error

Discussion created by shaun_weston-eagle-co-nz-esridist on May 18, 2011
Latest reply on Jul 2, 2011 by shaun_weston-eagle-co-nz-esridist
I am having a very frustrating issue with changing the source of image for a picture using python. I just keep getting the below error:

Traceback (most recent call last):
  File "E:\Current Projects\Kapiti Coast District Council\Scripts\", line 20, in <module>
    elm.sourceImage = Pic1976
  File "D:\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\", line 77, in _set
    return setattr(self._arc_object, attr_name, ao)
IOError: LayoutElementObject: Unexpected error
LayoutElementObject: Unexpected error
Completed script ChangePicture...
Failed to execute (ChangePicture).

It runs fine if I reference a picture with an element name that isn't actually present in the mxd, but whenever I try and change the source path for an image that is in the mxd, it stuffs up and I just can't figure out why! My code is below:

import arcpy, os, string


    #Read input parameters from script tool
    mxdPath = arcpy.GetParameterAsText(0)
    #Reference Map Document
    mxd = arcpy.mapping.MapDocument(mxdPath)
    Pic1976 = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")[0]  
    Pic2003 = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT")[1]

    elm = arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT", "Pic1976")[0]
    elm.sourceImage = Pic1976


except Exception, e:
  import traceback
  map(arcpy.AddError, traceback.format_exc().split("\n"))