2
$\begingroup$

I'm attempting to add a Color Attribute to each selected object, Here's the simple code:

import bpy 
lego = bpy.context.selected_objects
for x in lego:
    bpy.ops.geometry.color_attribute_add()

Which to my knowledge should iterate through each object and add the color attribute once, instead running the script it seems to run over only the active selection and add the color attribute repeatedly for the amount of objects selected.

So instead of each object having it once, i end up with 1 object having the attribute houndreds of times.

Is this a bug that i should report or is there a specific way i should be adding this attribute in scripts that im unaware of?

(Specifically the Color Attribute located in the object data properties tab not refering to materials)

Thanks!

$\endgroup$
2
  • $\begingroup$ several operators only function on the active object. Add bpy.context.view_layer.objects.active = x at the start of your for loop. $\endgroup$
    – Ratt
    Commented Sep 17, 2023 at 2:33
  • $\begingroup$ That worked thanks for your help @Ratt legend $\endgroup$ Commented Sep 17, 2023 at 2:41

1 Answer 1

1
$\begingroup$

Thanks to @Ratt for the solution:

Adding the following line of code to the for loop solved the issue:

bpy.context.view_layer.objects.active = x
$\endgroup$

You must log in to answer this question.

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