Skip to content

Instantly share code, notes, and snippets.

@pcote
Created October 23, 2011 18:06
Show Gist options
  • Save pcote/1307658 to your computer and use it in GitHub Desktop.
Save pcote/1307658 to your computer and use it in GitHub Desktop.
An example of Python scripting using gease pencil scripting for Blender. A partial re-invention of the "Convert Grease Pencil" operator.
def make_basic_curve():
crv = bpy.data.curves.new("crv", type="CURVE")
crv_ob = bpy.data.objects.new("crv_ob", crv)
return crv, crv_ob
scnobs = bpy.context.scene.objects
pencil = bpy.data.grease_pencil[0]
for i, stroke in enumerate(pencil.layers[0].active_frame.strokes):
crv, crv_ob = make_basic_curve()
scnobs.link(crv_ob)
stroke_points = pencil.layers[0].active_frame.strokes[i].points
data_list = [ (point.co.x, point.co.y, point.co.z)
for point in stroke_points ]
points_to_add = len(data_list)-1
flat_list = []
for point in data_list:
flat_list.extend(point)
spline = crv.splines.new(type="BEZIER")
spline.bezier_points.add(points_to_add)
spline.bezier_points.foreach_set("co", flat_list)
for point in spline.bezier_points:
point.handle_left_type="AUTO"
point.handle_right_type="AUTO"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment