I have based my script on this answer : How can I convert a Grease Pencil object to curve or mesh without operators?

And the script works well when only converting the gpencil object to curves. But when I try to run it before or after the rendering process with the modifications I added (to create new curves at each frames and delete the last ones to be replaced at the next frame).

I don't get what's wrong with my script (sorry if it seems obvious to you I'm still learning), how can I make it work ?

import bpy

def main():
    gpencil_object = bpy.data.objects["LineArt"]

def new_convert_curve_object(collection, name):    
    curve = bpy.data.curves.new(name=name, type="CURVE")
    curve.dimensions = "3D"
    convert_object = bpy.data.objects.new(name=name, object_data=curve)
    return convert_object

def convert_gpencil_to_curve(gpencil_object):
    gp_col = gpencil_object.users_collection[0]
    gp = gpencil_object.data
    for layer in gp.layers:               
        obj = new_convert_curve_object(gp_col, f"LineArt_curve")
        for frame in layer.frames:
            for stroke in frame.strokes:
                spline = obj.data.splines.new(type="POLY")                   
                spline.points.add(len(stroke.points) - 1)
                for i, point in enumerate(stroke.points):
                    spline.points[i].co = [v for v in point.co] + [1]

def delete_curve():
    if "LineArt" in bpy.data.objects:



You must log in to answer this question.