0

I'm trying to delete a Picture Element from 45 MXDs. This code is a start for me:

import arcpy
from arcpy import env

env.workspace = r"G:\PROJECTS\landuse\gis"
for mxdname in arcpy.ListFiles("*.mxd"):
    mxd = arcpy.mapping.MapDocument(
                r"G:\PROJECTS\landuse\gis\\" + mxdname)
    for elm in arcpy.mapping.ListLayoutElements(mxd,"PICTURE_ELEMENT"):
        if elm.name == "F:\GIS\practical_shapefile\notes\aer1_logo1.jpg":
            elm.sourceImage =r"F:\GIS\practical_shapefile\general\esd_logo1.jpg"
            mxd.save()
del mxd

I read:

but didn't find any hint how to do it.

  • 1
    Don't think you can actually delete a layout element with arcpy.mapping. Maybe, you could try playing with its size? For instance, try setting its elementHeight/elementWidth to 0. Or, as you are probably already doing, try setting its source to an empty or even non-existent image. Just few hints that might work... – umbe1987 Aug 26 at 9:14
1

It appears you cannot add or remove picture elements using ArcPy. If it's acceptable you can use a work around and set the element height to 0.

pict = arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT")[0]
pict.elementHeight = 0

Here's a red bar picture element which disappears once I set its height to zero. It sounds like you're working outside the mxd but if not make sure you refresh the view to see the results.

enter image description here

enter image description here

  • yes- i work on outside python file and i want to delete the image, then to export it with python- but with no red sign as you mention. how can do it? – newGIS Sep 1 at 8:51

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.