1
$\begingroup$

I try to load in an image sequence as background image with python. I managed to load it and set the source as sequence, however when i try to set its frame duration according to the number of images in the sequence, I get an error saying that the attribute is read-only. Can I change this attribute in another way and if not, how can I tell Blender to use it as image sequence?

My code so far:

path="C:\Users\user\Desktop\image0001.png"
img = bpy.data.images.load(path)
img.source = "SEQUENCE"

Prints an error:

img.frame_duration = 50

Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
AttributeError: bpy_struct: attribute "frame_duration" from "Image" is read-
only
$\endgroup$

2 Answers 2

1
$\begingroup$

frame duration is a calculated value and cannot be set directly.

frame_duration = frame_end - frame_start

In order to change the frame_duration of the sequence you need to change the frame_start and/or frame_end. This makes sense as Blender cannot decide for you which frames you don't want to see (cut from the start or cut from the end, or from the middle, or ....).

# cut the start of the sequence
desired_frame_duration = 50
img.frame_start += img.frame_end - desired_frame_duration

# cut the end of the sequence
desired_frame_duration = 50
img.frame_end = img.frame_start + desired_frame_duration
$\endgroup$
2
  • 1
    $\begingroup$ Seems the frame_start and frame_end no longer exist for image datablocks in Blender 2.8x. Is there another way this can be achieved? $\endgroup$ Commented Sep 3, 2020 at 14:53
  • $\begingroup$ try to use image_user. I add image to ShaderNodeTexEnvironment then ShaderNodeTexEnvironment.image_user.frame_start can bet set. $\endgroup$ Commented Dec 2, 2020 at 7:50
1
$\begingroup$

If the image editor is used in one of the visible areas of the current workspace, it can be iterated through bpy.context.screen.areas to find the one with type IMAGE_EDITOR. The image that is shown in the editor can be set through the space of the area.

path="C:\Users\user\Desktop\image0001.png"
img = bpy.data.images.load(path)

for area in bpy.context.screen.areas:
    if area.type == 'IMAGE_EDITOR':
        area.spaces.active.image = img
        img.source = 'SEQUENCE'
        area.spaces.active.image_user.frame_duration = 800
    

And if the plugin is in context, i.e in menu or button of a viwer node then there is no need to iterate through anymore. As the cursor is already in context menu. In this case the plugin script should be:

path="C:\Users\user\Desktop\image0001.png"
img = bpy.data.images.load(path)

bpy.context.area.spaces.active.image = img
img.source = 'SEQUENCE'
bpy.context.area.spaces.active.image_user.frame_duration = 800
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .