1
$\begingroup$

I’m trying to use the API to add two buttons/hotkeys to Blender that will quickly darken and lighten the current color that Vertex Color mode uses when doing Set Vertex Color (Shift+K).

Basically, get the current color, alter it, set the current color.

I can’t figure out how to get/set this color though.

I tried the API call below, but it doesn’t set the color that Shift+K will use next:

bpy.context.tool_settings.vertex_paint.brush.color = Color((1.0, 0.0, 0.0))

Any help is very appreciated, thank you!

$\endgroup$
1
  • $\begingroup$ Explain your problem in detail $\endgroup$
    – Karan
    Commented Feb 14, 2023 at 16:39

1 Answer 1

1
$\begingroup$

Note that brush.secondary_color not shown in header in Blender < 3.2

get colors:

# get brush.color
brush_color_first = bpy.context.tool_settings.vertex_paint.brush.color
print("primary color:", brush_color_first)

# get brush.secondary_color
brush_color_second = bpy.context.tool_settings.vertex_paint.brush.secondary_color
print("secondary color:", brush_color_second)

change colors: float array of 3 items in [0, 1], default (1.0, 1.0, 1.0)

# change brush.color  
bpy.context.tool_settings.vertex_paint.brush.color = (1.0, 0.0, 1.0) 

# change brush.secondary_color  
bpy.context.tool_settings.vertex_paint.brush.secondary_color = (0.0, 1.0, 0.0)

set colors: Fill the active vertex color layer with the current paint color (primary/secondary)

bpy.ops.paint.vertex_color_set()
$\endgroup$
1
  • $\begingroup$ Ah, I was declaring my new colors incorrectly. Thank you! $\endgroup$ Commented Feb 15, 2023 at 18:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .