Iterate through all objects in selection, iterate through all material slots using a nested loop to get the material reference and finally set the property:
import bpy
C = bpy.context
# Iterate through all objects in selection
for ob in C.selected_objects:
if ob.type not in ('LIGHTS', 'CAMERA', 'VOLUME'): # OPTIONAL
# Iterate through all material slots
for slot in ob.material_slots:
if slot.material is not None:
# Set the property
slot.material.show_transparent_back = False
slot.material.diffuse_color = (1.0, 0.0, 0.0, 1.0)
slot.material.use_backface_culling = True
# ... whatever
In case some materials are assigned to several objects, you can also create a set out of unique materials and assign the value per item of the set instead of iterating through the same slots over and over again which will improve performance (thanks to @batFINGER).
import bpy
C = bpy.context
# Create the set
mats = set(slot.material for o in C.selected_objects for slot in o.material_slots)
# Iterate through all unique materials
for mat in mats:
# Set the property
mat.show_transparent_back = False
mat.diffuse_color = (0.0, 1.0, 0.0, 1.0)
mat.use_backface_culling = True
# ... whatever
Related