2
$\begingroup$

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()

Is this a problem with my script, or with bpy.ops.mesh.customdata_custom_splitnormals_clear()? I am trying to make this a script because selecting everything an Alt clicking the button for it does not work on all objects either.

$\endgroup$
0

2 Answers 2

3
$\begingroup$

Here the code ported to 2.8 ;)

import bpy

context = bpy.context
scene = context.scene

selected_mesh_objects = [o for o in context.selected_objects if o.type == 'MESH']

ao = context.view_layer.objects.active

for o in selected_mesh_objects:
    context.view_layer.objects.active = o
    r = bpy.ops.mesh.customdata_custom_splitnormals_clear()
    print(o.name, r)

# change ao back to original   
context.view_layer.objects.active = ao
$\endgroup$
4
$\begingroup$

Set the active object in the loop, as it appears bpy.ops.mesh.customdata_custom_splitnormals_clear only works on the active object. Not on all selected.

import bpy

context = bpy.context
scene = context.scene

selected_mesh_objects = [o for o in context.selected_objects if o.type == 'MESH']

ao = context.active_object

for o in selected_mesh_objects:
    scene.objects.active = o
    r = bpy.ops.mesh.customdata_custom_splitnormals_clear()
    print(o.name, r)

# change ao back to original   
scene.objects.active = ao

Note added print statement with name and operator "result". A {'FINISHED'} set will indicate object had custom split normals and they have been removed.

$\endgroup$
1
  • $\begingroup$ Last suggestion doesn't work in latest 2.8. I think the problem is in the new API. Can you help with upgrading the code? I want to apply my script to the selected active object. $\endgroup$ Apr 24, 2019 at 16:39

You must log in to answer this question.

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