test
🧩 Syntax:
import bpy
# Clear existing objects and animation data
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()
bpy.ops.anim.select_all(action='DESELECT')
bpy.ops.anim.keyframe_clear()
# Create a circle
bpy.ops.mesh.primitive_circle_add(radius=1, location=(0, 0, 0))
circle = bpy.context.object
# Add a curve modifier to the circle
bpy.ops.object.modifier_add(type='CURVE')
bpy.context.object.modifiers["Curve"].object = bpy.context.scene.collection.objects["BezierCurve"]
# Create a Bezier curve
bpy.ops.curve.primitive_bezier_curve_add()
bezier_curve = bpy.context.object
# Set up keyframes for animating the curve
bezier_curve.data.use_deform_bounds = True
bezier_curve.data.resolution_u = 6
bezier_curve.data.fill_mode = 'FULL'
bezier_curve.data.bevel_depth = 0.05
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 100
# Animate the knot formation
knot_frames = 100 # Number of frames to form the knot
for i in range(knot_frames):
frame = i + 1
bpy.context.scene.frame_set(frame)
# Manipulate the control points of the Bezier curve to form the knot
bezier_curve.data.splines[0].points[0].co = (0, 0, 0)
bezier_curve.data.splines[0].points[0].handle_right = (1, 0, 0)
bezier_curve.data.splines[0].points[1].co = (2, 0, 0)
bezier_curve.data.splines[0].points[1].handle_left = (1, 0, 0)
bezier_curve.data.splines[0].points[1].handle_right = (2, 0, 0)
bezier_curve.data.splines[0].points[2].co = (2, 2, 0)
bezier_curve.data.splines[0].points[2].handle_left = (2, 0, 0)
bezier_curve.data.splines[0].points[2].handle_right = (2, 2, 0)
bezier_curve.data.splines[0].points[3].co = (0, 2, 0)
bezier_curve.data.splines[0].points[3].handle_left = (2, 2, 0)
# Keyframe the control points
for point in bezier_curve.data.splines[0].points:
point.keyframe_insert(data_path="co")
# Set up the rendering settings
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.cycles.device = 'CPU'
bpy.context.scene.render.image_settings.file_format = 'PNG'
bpy.context.scene.render.filepath = '/path/to/save/animation'
bpy.context.scene.render.image_settings.color_mode = 'RGBA'
# Render the animation
bpy.ops.render.render(animation=True)