Set vertex color on selected verts?

I have a selection of verts that I want to apply a black color to. How can I do this?
Ive tried using the face selection mask, but that doesnt work on my vertex selection…
Any ideas?

Would love to be able to set the vert color from the edit mode like in 3ds max :smiley:

Face selection masking doesn’t work because vertex colors are stored per-vertex per-face (i.e. same vertex in different faces can have different colors, thus the Paint -> Set Vertex Colors only affects fully selected faces). If you want to set the color for vertices in all faces they belong to, here’s a small add-on to do just that:


#
# Save into your addons directory as mesh_set_vertex_color.py
# and activate the add-on in user preferences
#

bl_info = {
    "name" : "Set Vertex Color",
    "author" : "Stanislav Blinov",
    "version" : (1, 0, 0),
    "blender" : (2, 74, 0),
    "description" : "Set vertex color for selected vertices",
    "category" : "Mesh",}

import bpy
import bmesh

class MESH_xOT_SetVertexColor(bpy.types.Operator):
    bl_idname = "mesh.addon_set_vertex_color"
    bl_label = "Set Vertex Color..."
    bl_options = {'REGISTER', 'UNDO'}
    
    color = bpy.props.FloatVectorProperty(
        name = "Color",
        description = "Color",
        subtype = 'COLOR',
        min = 0.0,
        max = 1.0)
    
    @classmethod
    def poll(cls, context):
        return context.mode == 'EDIT_MESH'
    
    def execute(self, context):
        bm = bmesh.from_edit_mesh(context.object.data)
                
        verts = [ v for v in bm.verts if v.select ]
        
        if verts:
            colors = bm.loops.layers.color.active
            if not colors:
                colors = bm.loops.layers.color.new("Col")
                
            for v in verts:
                for loop in v.link_loops:
                    loop[colors] = self.color
                    
            bmesh.update_edit_mesh(context.object.data)
                
        return {'FINISHED'}
    
    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self)
   
def register():
    bpy.utils.register_class(MESH_xOT_SetVertexColor)
    
def unregister():
    bpy.utils.unregister_class(MESH_xOT_SetVertexColor)
    
if __name__ == "__main__":
    register()

As the comment at the top says, save it as mesh_set_vertex_color.py in your add-ons directory and activate the add-on (will appear as “Set Vertex Color” in “Mesh” category). You will find the operator “Set Vertex Color…” using the spacebar search menu in edit mode. I’ve thought about adding it to Mesh -> Vertices menu, but it doesn’t work if the menu is invoked via the Ctrl+V hotkey.

This should probably be submitted to some existing add-on collection, I’ll post an update if/when that happens.

I should note that when I was writing it, I’ve encountered an issue, so be careful with this add-on. Until that is fixed, it’d be a good idea to add new vertex color layers outside of edit mode.

1 Like

Cheers, will give this a go!