I need a script to set a certain Blend Mode or Shadow Mode for all materials that are shared across all selected objects. If this is too complex, I’d still be very happy to change Blend Mode or Shadow Mode for all materials in scene.
E.g. I want them all to be Blend Mode > Hashed. When there are hundreds of materials across the scene, it gets quite time-consuming to do it manually, one by one.
Thank you, but the script fails in the first line. Are you sure it’s up to the new Python API (3.9), introduced in Blender 2.93? I am currently using Blender 3.0.
Shouldn’t there be a first line with “import bpy”? I added it, but the script fails anyway.
This works fine in the 3.1 Python console, setting the Blend Mode to Alpha Hashed:
import bpy
for material in bpy.data.materials:
material.blend_method = 'HASHED'
The Python version(which is not the version of the Blender API) would not affect this. Python is space specific though, so make sure you put a tab or two/four spaces before starting the last line.
If you still get an error, please post it instead of just saying it doesn’t work. If you don’t get any error, then screenshot what you’re talking about and point out where it’s wrong and what it should say.
@michalpe, I understand if you encountered an error trying to run this from a Blender Text Editor. The script I posted works in Blender 3.0.1 if you copy and paste it in the Python Console. The Python Console is the window with the blue text that says PYTHON INTERACTIVE CONSOLE 3.9.7 and the >>> prompt.
The things that you get for free with the interactive console that you don’t get in a Blender Text Editor window have already been mentioned: 1) the bpy module has already been imported, so you don’t have to type that every time, and 2) there are 2 convenience variables for objects that save you from having to type their full names every time. I used one of those in my script which wouldn’t work in a Blender Text Editor unless you explicitly assigned D = bpy.data in your code.
If you wanted to use my script as a Python module that you could run from the Blender Text Editor, here’s how:
In a Blender Text Editor, click Text > New.
in the Name field, type hashed.py (the naming convention for Python modules is short, all lowercase names)
Enter the following text:
import bpy
D = bpy.data
for material in D.materials:
material.blend_method = 'HASHED'
Click Text > Save and choose a location where you’d like to store your scripts for convenience.
Click Text > Run Script however often you like.
My apologies if I wasn’t clearer in my original post.