Select to view content in your preferred language

Python Picture_Element Error

899
1
05-18-2011 03:22 PM
ShaunWeston
Frequent Contributor
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\PictureElement.py", line 20, in <module>
    elm.sourceImage = Pic1976
  File "D:\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\_base.py", 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

try:

    #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

          
    mxd.save()

except Exception, e:
  import traceback
  map(arcpy.AddError, traceback.format_exc().split("\n"))
  arcpy.AddError(str(e))
Tags (2)
0 Kudos
1 Reply
ShaunWeston
Frequent Contributor
Didn't exactly figure this one out, so I just changed how I was reading the path

    for row in rows:
        Pic1976 = row.FILE
        Pic2003 = row.FILE_1

Used the above code instead to read directly from the attribute table.
0 Kudos