Is there any way through the Python API to determine if a grease pencil stroke/point has been drawn in material or vertex paint mode?

As far as I can tell, if a stroke has been created in material mode the vertex_color attr will always yield a value of (0.0, 0.0, 0.0, 1.0) even if the material's stroke color is some other value...which is to be expected since the material's stroke color is driving the point colors.

But if the point's values are set using Python, it seems to sever the connection between the material and the vertex color as if the points were drawn in vertex mode and changing the material no longer affects those vertices. I suppose this makes sense too since you're explicitly redefining the color of the vertex.

Is this state change stored anywhere that can be accessed via Python? I don't see anything listed in the API on any of grease pencil classes that might be queried. Maybe it's some other type of mechanism driving this that can be queried?

  • $\begingroup$ Hello, I didn't test it but it seems this flag could be it ? docs.blender.org/api/current/… $\endgroup$
    – Gorgious
    Jan 2, 2023 at 8:00
  • $\begingroup$ Thanks!...I was looking at that too but that returns if the stroke is in Vertex Paint mode (vs Draw or Edit mode). There's a command in the material section pulldown called Convert Materials to Color Attribute which basically converts all materials to vertex color as if they were created in vertex color mode, so I thought there would be some clues there. I'm not very fluent in C but looking at the source code, it seems like it's just cleaning up the materials and then setting the vertex color. Must be something further down in the core code that's doing the disconnect. $\endgroup$
    – blender8r
    Jan 2, 2023 at 14:00

1 Answer 1


Interesting question. It seems that for a stroke point the material color is used when the alpha value of the vertex color is 0. In the source code I found this test:

/* If not using Vertex Color, use the material color. */
if (... && (point->vert_color[3] == 0.0f) && ...) {

So in Python we can test it like this:

import bpy

stroke = bpy.data.grease_pencils['Stroke'].layers['Lines'].active_frame.strokes[0]

# Testing for material color
for index, point in enumerate(stroke.points):
    if point.vertex_color[3] == 0:
        print('Material color is used for point', index)

# Or: setting stroke point to material color
stroke.points[0].vertex_color[3] = 0
  • $\begingroup$ Ah, that's what I was looking for. Thanks! I suspected it was down at the stroke point level because when you use the Vertex Tint tool, tinted vertices become disconnected from the material while the rest do not. $\endgroup$
    – blender8r
    Jan 3, 2023 at 13:10

You must log in to answer this question.

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