premise
The code below is intended to duplicate an object and change the vertex color of the duplicated object. Select the object called "ic" and run it. Ultimately, I want to change the color to a gradient while continuously generating dozens of objects, so this code is I extracted only the problematic elements.
problem
I found that it works fine in Blender 3.5, but in Blender 4.1 there is a problem where the color of the original object changes. Is this a specification change in 4.0 or later? If so, how can I fix it so it will work properly in 4.1?
import colorsys
import bpy
import random
def duplicate_move_and_rename(obj, x, y, z):
bpy.ops.object.duplicate_move(TRANSFORM_OT_translate={"value":(x, y, z)})
return
obj = bpy.context.active_object
# -------------------------------------------------
duplicate_move_and_rename(obj, -2, 0, 0)
obj2 = bpy.context.active_object;
vc2 = obj2.data.vertex_colors[0].data
hue = 1.0
print(hue)
saturation = 1.0
value = 1.0
for polygon2 in obj2.data.polygons:
for i, v in zip(polygon2.loop_indices, polygon2.vertices):
vc2[i].color = colorsys.hsv_to_rgb(hue, saturation, value)+(1,)