Skip to content

Instantly share code, notes, and snippets.

import bpy
gpencil_data = bpy.data.grease_pencils.new("GPencil")
gpencil = bpy.data.objects.new(gpencil_data.name, gpencil_data)
bpy.context.collection.objects.link(gpencil)
gp_layer = gpencil_data.layers.new("lines")
gp_frame = gp_layer.frames.new(bpy.context.scene.frame_current)
@blender8r
blender8r / gpencil_points.py
Last active January 8, 2022 14:53
Generates a Blender grease pencil stroke containing random points
# Generates grease pencil points with random position, size and color
import bpy
import random
sel_obj = None
sel_objs = bpy.context.selected_objects
if sel_objs:
@blender8r
blender8r / gpencil_line.py
Last active January 8, 2022 14:44
Generates a Blender grease pencil line
# Generates grease pencil line
import bpy
import random
def line(gp_frame, start_pos, end_pos, num_pts):
gp_stroke = gp_frame.strokes.new()
gp_stroke.line_width = 30
@blender8r
blender8r / gpencil_w_noise.py
Last active January 8, 2022 14:52
Generates a grease pencil line with noise on vertical axis
# Generates grease pencil line with random noise on z axis
import bpy
import random
def line(gp_frame, start_pos, end_pos, num_pts):
gp_stroke = gp_frame.strokes.new()
gp_stroke.line_width = 30
@blender8r
blender8r / gpencil_better_noise.py
Last active January 8, 2022 14:51
Generates a grease pencil line with noise (alternate method)
# Generates grease pencil line with random noise on z axis (alternate method)
import bpy
import random
def line(gp_frame, start_pos, end_pos, num_pts):
gp_stroke = gp_frame.strokes.new()
gp_stroke.line_width = 30
@blender8r
blender8r / gpencil_wiggly_line.py
Last active January 8, 2022 14:46
Generates a grease pencil line that wanders noisily in all directions
# Generates grease pencil line with random noise on x and z axes
import bpy
import random
from mathutils import Vector
def line(gp_frame, start_pos, end_pos, num_pts):
gp_stroke = gp_frame.strokes.new()
gp_stroke.line_width = 30
@blender8r
blender8r / gpencil_add_noise_modifier.py
Last active January 8, 2022 14:44
Adds a noise modifier to a grease pencil stroke
# adds a grease pencil noise modifier to the selected grease pencil object
import bpy
import random, math
from mathutils import Vector
def line(gp_frame, start_pos, end_pos, num_pts):
gp_stroke = gp_frame.strokes.new()
gp_stroke.line_width = 30
import bpy
from math import pi, sin, cos
num_points = 48
center = (0.0, 0.0, 0.0)
def ellipse(gp_frame, center, radius_x, radius_z, num_points):
gp_stroke = gp_frame.strokes.new()
import bpy
from math import pi, sin, cos
num_points = 48
center = (0.0, 0.0, 0.0)
def ellipse(gp_frame, center, radius_x, radius_z, num_points):
gp_stroke = gp_frame.strokes.new()
import bpy
from math import pi, sin, cos
num_points = 10
center = (0.0, 0.0, 0.0)
def star(gp_frame, center, radius_x, radius_z, num_points, offset=0.75):
gp_stroke = gp_frame.strokes.new()
gp_stroke.line_width = 30
gp_stroke.use_cyclic = True