Skip to content

Instantly share code, notes, and snippets.

@blender8r
Created November 9, 2023 12:47
Show Gist options
  • Select an option

  • Save blender8r/c9640ee6ca0ae7fa01ea31a6a267caef to your computer and use it in GitHub Desktop.

Select an option

Save blender8r/c9640ee6ca0ae7fa01ea31a6a267caef to your computer and use it in GitHub Desktop.
Creates two grease pencil lines in Blender
import bpy
def line(gp_frame, start_pos, end_pos, num_pts):
gp_stroke = gp_frame.strokes.new()
gp_stroke.line_width = 30
gp_stroke.points.add(count=num_pts)
start_x = start_pos[0]
start_z = start_pos[2]
end_x = end_pos[0]
end_z = end_pos[2]
step_x = (end_x - start_x) / num_pts
step_z = (end_z - start_z) / num_pts
i = 0
while i < num_pts:
gp_stroke.points[i].co = (start_x + (step_x*i), 0.0, start_z + (step_z*i))
i += 1
sel_obj = None
sel_objs = bpy.context.selected_objects
if sel_objs:
sel_obj = sel_objs[0]
if sel_obj is not None and sel_obj.type == 'GPENCIL':
gpencil = sel_obj.data
gp_layer = gpencil.layers.active
gp_frame = gp_layer.frames[0]
gp_frame.clear()
line(gp_frame, (-2.0, 0.0, 0.0), (2.0, 0.0, 0.0), 20)
line(gp_frame, (-2.0, 0.0, 1.0), (2.0, 0.0, 1.0), 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment