1
$\begingroup$

Below is the code that is for flipping the vertex on an object. I want it so I can select all objects and run the script it does it to all the objects selected instead of doing them individually. If someone could edit it or tell me how to fix it that would be greatly appreciated.

import bpy

obj = bpy.context.active_object

for ipoly in range(len(obj.data.polygons)):
    for idx, ivertex in enumerate(obj.data.polygons[ipoly].loop_indices):
        ivert = obj.data.polygons[ipoly].vertices[idx]
        col = obj.data.vertex_colors.active.data[ivertex].color
        obj.data.vertex_colors.active.data[ivertex].color = tuple(1-x for x in col)
$\endgroup$

1 Answer 1

0
$\begingroup$

You can get all selected objects in:

objs = bpy.context.selected_objects

then just make a loop:

for obj in objs:

and then your code.

Done:

import bpy

objs = bpy.context.selected_objects
for obj in objs:
    for ipoly in range(len(obj.data.polygons)):
        for idx, ivertex in enumerate(obj.data.polygons[ipoly].loop_indices):
            ivert = obj.data.polygons[ipoly].vertices[idx]
            col = obj.data.vertex_colors.active.data[ivertex].color
            obj.data.vertex_colors.active.data[ivertex].color = tuple(1-x for x in col)
$\endgroup$
1
  • $\begingroup$ thanks! i got it to work! $\endgroup$ Commented Jun 7, 2020 at 6:50

You must log in to answer this question.

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