Created
May 16, 2023 13:14
-
-
Save jmpinit/30d9422af95f8fdc8a2345ffbebcdefd to your computer and use it in GitHub Desktop.
Draw a squiggle in Blender's Grease Pencil mode via the Python API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
# Create a new Grease Pencil object to hold the drawing | |
bpy.ops.object.gpencil_add(location=(0, 0, 0)) | |
grease_pencil = bpy.context.object | |
grease_pencil.name = "ScriptedGreasePencil" | |
layer = grease_pencil.data.layers.new("Layer") | |
grease_pencil.data.layers.active = layer | |
frame = layer.frames.new(1) | |
stroke = frame.strokes.new() | |
# Set the thickness of the stroke (optional) | |
stroke.line_width = 100 | |
# Define the points of the squiggle | |
points = [(0, 0), (1, 1), (2, -1), (3, 0)] | |
# Add points to the stroke | |
for x, y in points: | |
stroke.points.add(1) | |
stroke.points[-1].co = (x, y, 0) | |
# Update the view to see the changes | |
bpy.context.view_layer.update() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment