How to set custom vertex normals for certain vertices using python? I am struggling to set custom vertex normal vector just for certain/selected vertices in an object with python. I searched through the documentation and forums but nothing really helps so far.

This question/answer answers only to how to set split normal to a whole object. However, I want to set custom normals to just some parts of the object. See the picture below:



Q: How can I add custom normals just to certain vertices in and object?

Would be helpful if someone could share something simple as possible.
Example of assigning custom normals based on vertex selection. It's just a slight modification of the code given in this answer and assigns a custom vector to vertices in selection.



Run the script in Object Mode and enable show_split_normal property in Edit Mode:

import bpy

context = bpy.context
ob = context.object
me = ob.data

me.use_auto_smooth = True

# Normal custom verts on each axis
me.normals_split_custom_set([(0, 0, 0) for l in me.loops])

# Set normal for selected vertices
normals = []
for v in me.vertices:
    if v.select:
    # if v.index in (0, 1, 4): # Alternatively you can ask for certain indices
        normals.append((0, 0, -0.5))
    else:
        normals.append(v.normal)

# make csn's all face up.  
me.normals_split_custom_set_from_vertices(normals)

#me.free_normals_split()


Note: As of 2.8x show_split_normal property is part of the Overlays menu: