Last active
November 7, 2017 16:59
-
-
Save n1ckfg/2edcd29318808f3b25f1bd271e08d9a5 to your computer and use it in GitHub Desktop.
Blender Grease Pencil 2 utility functions
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 getActiveGp(_name="GPencil"): | |
try: | |
pencil = bpy.context.scene.grease_pencil | |
except: | |
pencil = None | |
try: | |
gp = bpy.data.grease_pencil[pencil.name] | |
except: | |
gp = bpy.data.grease_pencil.new(_name) | |
bpy.context.scene.grease_pencil = gp | |
print("Active GP block is: " + gp.name) | |
return gp | |
def getActivePalette(): | |
gp = getActiveGp() | |
palette = gp.palettes.active | |
if (palette == None): | |
palette = gp.palettes.new(gp.name + "_Palette", set_active = True) | |
if (len(palette.colors) < 1): | |
color = palette.colors.new() | |
color.color = (0,0,0) | |
print("Active palette is: " + gp.palettes.active.name) | |
return palette | |
def getActiveColor(): | |
palette = getActivePalette() | |
print("Active color is: " + "\"" + palette.colors.active.name + "\" " + str(palette.colors.active.color)) | |
return palette.colors.active | |
def createPoint(_stroke, _index, _point): | |
_stroke.points[_index].co = _point | |
_stroke.points[_index].select = True | |
_stroke.points[_index].pressure = 1 | |
_stroke.points[_index].strength = 1 | |
def testStroke(): | |
gp = getActiveGp() | |
palette = getActivePalette() | |
color = getActiveColor() | |
color.color = (1.0, 10.0, 0.0) | |
layer = gp.layers.new("TestLayer") | |
frame = layer.frames.new(bpy.context.scene.frame_current) | |
stroke = frame.strokes.new(color.name) | |
stroke.draw_mode = "3DSPACE" | |
stroke.points.add(2) | |
createPoint(stroke, 0, (0,0,0)) | |
createPoint(stroke, 1, (100,100,0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment