How do I delete/remove/replace an image using a script? I have a script that inserts three images (Image1, Image2, Image3) into a blend and then renders the video. It works great. The images show up exactly when and where they are supposed to.

The problem is that I want to be able to run the script as loop, picking up a different set of images each time through the loop. I have that part working just fine except...

The new images (Image1.001 - Image1.00n, Image2.001 - Image2.00n, Image3.001 - Image3.00n) simply overlay each other. Since I am using .png images with transparencies, this is a real problem. To be clear, these are foreground images, not a texture or anything similar.

I have tried everything I can find to delete, remove or replace the original images with the new ones via my script. Nothing I have found and tried has worked. I have to believe there is a way to do this.

Help??? Please.

Here is the relevant part of the code:

import bpy
import csv
import sys

csv_path = sys.argv[5]
file = open(csv_path, 'rU')
reader = csv.reader(file)

fnt = bpy.data.fonts.load('../fonts/Helvetica-Bold.ttf')

s = bpy.context.scene
sed = s.sequence_editor
sequences = sed.sequences

header = next(reader) # 1st line is header`

data = [ ]
for row in reader:
    name0 = row[0]
    pic2 = 'gfx/'+ row[2] # car(s)
    pathout = 'renders/proj003/' + row[4] + '.m4v'
    f = s.objects['Text']
    f.data.body = name0

    frame_start2 = 202
    frame_end2 = 266
    image_strip2 = sequences.new_image("Image2", pic2, 5, frame_start2)  
    image_strip2.frame_final_end = frame_end2
    image_strip2.blend_type = 'ALPHA_OVER'

    bpy.context.scene.render.filepath = pathout
    bpy.ops.render.render(animation=True)

bpy.ops.wm.quit_blender()








Image1
Image1.001
Image1.002

Note that 'Text' is replaced properly.
Some options

Result  with image strips are overlapping would indicate you are  setting start and end frames incorrectly in loop. If the idea is to make an animation of all the added strips,  not sure then why the render operator is inside the loop.

If that is how you want it, will need to  remove the image strip, replace the image strip, change the image strip data,  or batch render one make at a time

Remove the image sequence  Not sure if this will work, could be dodgy removing parts of a scene before it is fully rendered. Add code after render op.

 sequences.remove(image_strip2)


Secondly create the strip once, and change image settings, rather than creating new strip each time. This is equivalent of how you are resetting font body. (py console example) added strip with some dummy image, changed directory and element (image) name to a real one. 

&gt;&gt;&gt; im = sequences.new_image("Dummy", filepath="/tmp/xxx.png", channel=2, frame_start=3)
&gt;&gt;&gt; im.directory
'/tmp/'

&gt;&gt;&gt; im.directory = '/home/batfinger/Desktop/'
&gt;&gt;&gt; len(im.elements)
1

&gt;&gt;&gt; im.elements[0].filename
'xxx.png'

&gt;&gt;&gt; im.elements[0].filename = "images.jpeg"
&gt;&gt;&gt; im.update() # required???


Thirdly, rather than loop the csv inside the script, could set up a blend file to render a single car make, pass the make string and images to it and run from some shell script.

How to pass command line arguments to a Blender Python script?

For batch scripts there is no need to call the exit operator, as this is default behaviour.