0
$\begingroup$

I'm trying to copy N times a grease pencil frame and then iterate over their .drawing.strokes for doing some other things.

My problem:

Right after copying them, seems like some data is not there. When I try to access to the frame.drawing, this is None:

import bpy
C = bpy.context
    
f=C.active_object.data.layers.active.current_frame()

   
s=f.drawing.strokes[0]


gp = bpy.context.active_object.data
drawing = gp.layers.active.frames[0].drawing
layer = gp.layers.active
f = gp.layers.active.current_frame()
       
frame_to_copy = f.frame_number


_copied_frames = []
for i in range(20):
    print(i)
    new_frame_number = frame_to_copy+i+1
    print(i, new_frame_number, frame_to_copy)
    copied_frame = layer.frames.copy(frame_to_copy, new_frame_number, instance_drawing=False)
    _copied_frames.append(copied_frame)
    
for f in _copied_frames:
    print(f"{f.drawing = }")

I get this output:

f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = None
f.drawing = bpy.data.grease_pencils_v3['Stroke']...GreasePencilDrawing
f.drawing = bpy.data.grease_pencils_v3['Stroke']...GreasePencilDrawing
f.drawing = bpy.data.grease_pencils_v3['Stroke']...GreasePencilDrawing
f.drawing = bpy.data.grease_pencils_v3['Stroke']...GreasePencilDrawing
f.drawing = bpy.data.grease_pencils_v3['Stroke']...GreasePencilDrawing

Seems like only the last duplicated frames have their .drawing accessible.

Even though, when I then manually check each frame with the Blender python console, I'm able to access the .drawing as expected.

Seems like the data is not refreshed (?), or something like that. But I have no clue how to solve it.

Thank you for the help, much appreciated.

$\endgroup$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.