Created
October 23, 2011 18:06
-
-
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.
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
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