Script running only on Active object, not entire selection?


(Oscalon) #1

I am trying to make a script to Clear Custom Split Normals on all the objects I have selected. I have copied code from other scripts that run a command on all selected objects. However, this only seems to work on the Active Object, not the rest of the selection. Anyone know why?


import bpy

selected_objects = bpy.context.selected_objects

for selected_object in selected_objects:
    bpy.ops.mesh.customdata_custom_splitnormals_clear()


(TeaCrab) #2

bpy.ops.blahblah does not necessarily share all its characteristic with a different bpy.ops.brahbrah

Every bpy.ops.blah works differently. Most of them only work on the active object. Some of them work on multiple objects.

If you want such “active-only” operator to work on multiple objects, you need to set scene’s active object target to the object in your selections for that specific loop.


for obj in selected_objects:
    bpy.context.scene.objects.active = obj
    bpy.ops.mesh.customdata_custom_splitnormals_clear()

Basically, for each loop, you change the active object in the scene, and then execute the bpy.ops.whatever.

Typical Macro.