Skip to content

Instantly share code, notes, and snippets.

@blender8r
Last active June 1, 2023 14:26
Show Gist options
  • Select an option

  • Save blender8r/aeda68123228c829cda1033d2f09873b to your computer and use it in GitHub Desktop.

Select an option

Save blender8r/aeda68123228c829cda1033d2f09873b to your computer and use it in GitHub Desktop.
Converts the colors in a Blender Palette to individual Grease Pencil materials per-color
import bpy
from mathutils import Color
palette_name = bpy.context.tool_settings.gpencil_paint.palette.name
def create_palette_materials(gp, palette_name):
palette = bpy.data.palettes.get(palette_name)
if palette:
i = 0
while i < len(palette.colors):
mat_name = (palette_name + '_' + str(i))
mat = bpy.data.materials.new(mat_name)
bpy.data.materials.create_gpencil_data(mat)
gp.data.materials.append(mat)
mat.grease_pencil.show_stroke = True
mat.grease_pencil.show_fill = True
c = Color(palette.colors[i].color)
color_lin = c.from_srgb_to_scene_linear()
color = (color_lin[0], color_lin[1], color_lin[2], 1.0)
mat.grease_pencil.color = color
mat.grease_pencil.fill_color = color
i += 1
sel_obj = None
sel_objs = bpy.context.selected_objects
if sel_objs:
sel_obj = sel_objs[0]
if sel_obj and sel_obj.type=='GPENCIL':
gpencil = sel_obj
create_palette_materials(gpencil, palette_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment