20
$\begingroup$

I'd like to know if there's a way/add-on to convert curves to Grease Pencil strokes? I know you can convert in the other direction, but I can't find anything to create Grease Pencil strokes from curves.

In attempting to setup guides for a model I'm working on, did so using curves. I'm now thinking GP would have been the better option, and would rather not have to recreate my guides.

Rubbery Ducky curve guides (traced from reference photos)

$\endgroup$
  • $\begingroup$ Why don't you use the curves as guidelines instead? $\endgroup$ – Denis Aug 21 '15 at 15:36
18
+200
$\begingroup$

First convert your curves in to mesh objects, AltC > Mesh from Curve/Meta/Surf/Text.

Now just copy and paste the script below into blender's text editor, then with your object still selected press Run Script.

This script below will draw grease pencil strokes on the active object.

import bpy
from mathutils import Vector

obj = bpy.context.object
mesh = obj.data
scene = bpy.context.scene

pencil = bpy.data.grease_pencil.new("pencil")
scene.grease_pencil = pencil

layer = pencil.layers.new("layer", set_active=True)
frame = layer.frames.new(scene.frame_current)

for edge in mesh.edges:
    stroke = frame.strokes.new()
    stroke.draw_mode = '3DSPACE'

    stroke.points.add(2)
    stroke.points[0].co = obj.matrix_world * Vector(mesh.vertices[edge.vertices[0]].co)
    stroke.points[1].co = obj.matrix_world * Vector(mesh.vertices[edge.vertices[1]].co)

Thanks to CoDEmanX for his making a grease pencil through bpy answer.

$\endgroup$
  • 4
    $\begingroup$ or if you don't want to manually convert Curve to mesh first. use this: gist.github.com/zeffii/3ff4af3bb359c7d5eb0a $\endgroup$ – zeffii Aug 21 '15 at 17:05
  • $\begingroup$ I would love to see an example of this for blender 2.78. I have tried quite a few things that do not seem to work or crash blender. If I add each edge as a stroke, the next time gpencil is used it crashes blender. If I add all the verts individually to avoid the crash, I don't have a palette and if I add a palette via data...it crashes blender. $\endgroup$ – patmo141 Nov 19 '17 at 22:34
  • 1
    $\begingroup$ For blender 2.8, for curves and meshes, gist.github.com/iszotic/97eb7b479e38b51d8c02ec667cb0e559, use F3 or space to search for the operator $\endgroup$ – Iszotic May 29 at 13:45
11
$\begingroup$

You may also fake a look of a Grease Pencil. Select your curve, go to the Shape panel in a curve data header, change the Fill type to Full. Increase the Depth value under Bevel: to give a curve some thickness. Give it a new material also and change its settings as pictured below. Now you have an editable imitation of a Grease Pencil. enter image description here enter image description here

$\endgroup$
4
$\begingroup$

As a follow-up to @David script, I noticed that it creates a new Grease Pencil Data every time the script is run. This can make it annoying if you simply want each mesh as a new GP layer in the existing data.

To instead make it create a new layer on the existing Grease Pencil Data:

import bpy
from mathutils import Vector

def convert_curve_to_gp(obj):

    #---- CHANGED ----
    scene = bpy.context.scene
    mesh = obj.data

    layer = scene.grease_pencil.layers.new("layer", set_active=True)
    frame = layer.frames.new(scene.frame_current)
    #---- /CHANGED ----

    mesh = obj.to_mesh(scene, apply_modifiers=False, settings='PREVIEW')
    for edge in mesh.edges:
        stroke = frame.strokes.new()
        stroke.draw_mode = '3DSPACE'
        stroke.points.add(2)
        stroke.points[0].co = obj.matrix_world * Vector(mesh.vertices[edge.vertices[0]].co)
        stroke.points[1].co = obj.matrix_world * Vector(mesh.vertices[edge.vertices[1]].co)

    bpy.data.meshes.remove(mesh)

obj = bpy.context.object
convert_curve_to_gp(obj)
$\endgroup$
3
$\begingroup$

If you like to do this procedurally, you can use Sverchok Add-On to access the existing Grease Pencil data block and then modify it on the fly using nodes. A quick example, below I have 3 curves joined and then I draw Grease Pencil using this node tree:

GIST: https://gist.github.com/cfa9cf5b707b909965e2b4956ad0ce25

enter image description here

This will potentially change as Grease Pencil is currently being developed into real object.

$\endgroup$
  • 1
    $\begingroup$ This does not work for me in 0.5.9.6 Please provide a working Blender if you can. thanks $\endgroup$ – yarun can Dec 1 '18 at 20:07
  • $\begingroup$ Yes, actually something might have changed in Grease Pencil.. maybe with 2.8 the node will need to be revisited. I will check now... $\endgroup$ – Blender Sushi Guy Dec 5 '18 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.