Python Help

Does anybody have some sample code to loop through all objects in a scene and add a weighted normal to each object?

I’m just starting out in Python, but I can program in other languages so I would imagine setting up a loop for all objects in the scene (MESH) objects and then add the code to add the weighted normal for each object.

Any help would be greatly appreciated. I am currently using blender 2.93.1

Try this code - it adds the weighted normal modifier with the “keep sharp” option to all meshes. You can easily tweak it further.

> import bpy
> for obj in
>    if obj.type == 'MESH':
> = obj
>         bpy.ops.object.modifier_add(type='WEIGHTED_NORMAL')
>         bpy.context.object.modifiers["WeightedNormal"].keep_sharp = True
> = True


Thank you so much. This is exactly what I was looking for.

It worked like a charm. I had about 300 obj objects from a kitbash set.

Your little script was able to add a weighted normal to each of the 300 objects in less than 2 seconds.

Thanks again.