is it possible to delete a "PICTURE_ELEMENT" from a map document?

124
3
03-07-2019 10:43 AM
petegillard
New Contributor III

is it possible to delete a "PICTURE_ELEMENT" from a map document?

Have a map in 10.6 trying to delete a jpeg that's in the map.

Thanks#

0 Kudos
3 Replies
RandyBurton
MVP Regular Contributor

I've deleted text elements with arcpy, so it should be possible with something like (untested):

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")

for elm in arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT"):
elm.delete() # delete all picture elements
# or if using name or sourceImage properties
# if elm.name == "Photo":
# if elm.sourceImage == r"C:\Project\Data\NewPhoto.bmp":
# elm.delete()

mxd.save()
del mxd‍‍‍‍‍‍‍‍‍‍‍‍

See PictureElement for some information., but it doesn't really discuss .delete().

Hope this helps.

0 Kudos
RandyBurton
MVP Regular Contributor

I've had some time to do some tests.  While there is a delete() option for Text Elements, there is no such option for Picture Elements.  However, you can make the image disappear if you set either the width or height to 0.  Once it has been set to zero, it does not appear that you can bring the image back by adjusting the height/width.  The name, elementPositionX, elementPositionY and imageSource parameters still contain their original values. So this does not appear to be a clean deletion.  (If you are working inside ArcMap, you may need to refresh the view to see the changes.)

for elm in arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT"):
elm.elementHeight = 0.0 # setting this to 0 will also set elementWidth to 0‍‍
petegillard
New Contributor III

thanks,  i had tried the '.delete' without much luck. your other suggestion may work. We're re-doing some mxds made by a contractor and need to remove their logo from the maps (can always do it manually, but there are over 400 mxds !)

Thanks again,

Pete

0 Kudos