Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/3ff4af3bb359c7d5eb0a to your computer and use it in GitHub Desktop.
Save zeffii/3ff4af3bb359c7d5eb0a to your computer and use it in GitHub Desktop.
import bpy
from mathutils import Vector
def convert_curve_to_gp(obj):
pencil = bpy.data.grease_pencil.new("pencil")
scene = bpy.context.scene
scene.grease_pencil = pencil
mesh = obj.data
layer = pencil.layers.new("layer", set_active=True)
frame = layer.frames.new(scene.frame_current)
mesh = obj.to_mesh(scene, apply_modifiers=False, settings='PREVIEW')
verts = mesh.vertices
for edge in mesh.edges:
stroke = frame.strokes.new()
stroke.draw_mode = '3DSPACE'
stroke.points.add(2)
stroke.points[0].co = obj.matrix_world * verts[edge.vertices[0]].co
stroke.points[1].co = obj.matrix_world * verts[edge.vertices[1]].co
bpy.data.meshes.remove(mesh)
obj = bpy.context.object
convert_curve_to_gp(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment