Information about the mesh vertices colors is stored in its vertex_colors property, as well as in its color_attributes property. To remove vertex color data from the mesh, we need to clear these mesh properties.
First, let’s loop through all the selected objects:
1 |
for obj in bpy.context.selected_objects: |
If the mesh vertex colors were applied by painting with a brush in the “Vertex Paint” mode, the vertex color data is stored in the vertex_colors mesh property.
1 2 3 4 5 |
for col_attr in obj.data.vertex_colors: print(col_attr) # <bpy_struct, MeshLoopColorLayer("Attribute") at 0x00000182DE127B88> # ... |
The vertex_color property is a collection, so we can remove data from it by calling the remove() method and specifying the data to be removed as a parameter.
1 2 3 |
for obj in bpy.context.selected_objects: for col_attr in obj.data.vertex_colors: obj.data.vertex_colors.remove(col_attr) |
If we first created a container for vertex colors by clicking on the plus button in the Data Properties tab – Color Attributes, or, for example, transferred colors to mesh vertices from Geometry Nodes, the vertex colors data is stored in the special attribute.
To remove color attribute data, we can use the same remove() method on the color_attributes collection.
1 2 |
for attr in obj.data.color_attributes: obj.data.color_attributes.remove(attr) |
To take effect immediately, update the mesh
1 |
obj.update_tag() |
and redraw the viewport screen.
1 2 |
for area in bpy.context.screen.areas: area.tag_redraw() |
Now, for each of the selected meshes, all color data has been completely removed from its vertices.
Full code:
1 2 3 4 5 6 7 8 |
for obj in bpy.context.selected_objects: for col_attr in obj.data.vertex_colors: obj.data.vertex_colors.remove(col_attr) for attr in obj.data.color_attributes: obj.data.color_attributes.remove(attr) obj.update_tag() for area in bpy.context.screen.areas: area.tag_redraw() |