This may be a really stupid question, but it has me stumped.
How do I get my script to affect all objects in a scene and not just the active one? I’m new to Python and am practicing script writing to make semi-useful addons for Blender users. The one I’m making now (below) is very basic. It is a simple material editing setup. It works, just not exactly what I wanted.
Can someone explain how to set it to affect all objects in the scene?
import bpy
"""This script is for converting all materials in a scene to render in a black and white ink style."""
for material in bpy.data.materials:
#This changes the diffuse color and type. It also affects the color ramp.
material.diffuse_shader = 'TOON'
material.diffuse_color[0] = 1
material.diffuse_color[1] = 1
material.diffuse_color[2] = 1
material.diffuse_intensity = 1.0
material.diffuse_toon_size = 1.7
material.diffuse_toon_smooth = 0.0
material.use_diffuse_ramp = True
material.diffuse_ramp.elements[0].color = (0, 0, 0, 1)
material.diffuse_ramp.elements[1].color = (1, 1, 1, 1)
material.diffuse_ramp.elements[1].position = 0.5
material.diffuse_ramp_input = 'RESULT'
#This changes the specularity color and type. It also enables Receive Transparency.
material.specular_intensity = 0.0
material.specular_shader = 'TOON'
material.specular_color[0] = 1
material.specular_color[1] = 1
material.specular_color[2] = 1
material.specular_toon_smooth = 0.0
material.specular_toon_size = 0.0
material.use_transparent_shadows = True
Thank you to all that reply!
EDIT: Also, I know that this will effect all the materials, but I will be adding on to this script to effect mesh objects as well (Such as adding new materials by default). I am currently writing in additional code to add a UI Panel with buttons.