[ubuntu 22.04 | blender 4.4.1]
Hi, I’m using the Python API to enable Auto Smooth and set the angle to 15 degrees on all mesh objects. However, the shading result looks different from when I do it manually in the UI — manually it looks smooth, but via script, it’s still faceted.
Here’s the code I used:
import bpy
def apply_smooth_by_angle_to_all_meshes():
for obj in bpy.data.objects:
if obj.type != 'MESH':
continue
bpy.context.view_layer.objects.active = obj
obj.select_set(True)
bpy.ops.object.shade_auto_smooth()
if "Smooth by Angle" in obj.modifiers:
modifier = obj.modifiers["Smooth by Angle"]
modifier["Input_1"] = 0.261799 # 15 degrees
modifier["Socket_1"] = True
obj.select_set(False)
bpy.context.view_layer.update()
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
area.tag_redraw()
apply_smooth_by_angle_to_all_meshes()