5
$\begingroup$

I have an object with hundreds of materials, and I want to change the blend mode on all of them to opaque. I do not want to go through them individually, so I was wondering if there was a way through the console or somewhere else. I saw this page which was doing a similar things, but it id only changing the nodes. (Automatically change the properties of multiple materials) Thank you!

$\endgroup$
2
  • $\begingroup$ To clarify: are you asking about a variation on the python scripts you reference? And by opaque, what parameter on which node (in Shader Editor?) do you want to change (e.g., set Transmission to 0 on Principled BSDF shader node)? $\endgroup$
    – james_t
    Jan 23 at 18:31
  • $\begingroup$ I am talking about changing this parameter to opaque (imgur.com/a/DGOpXqb), it is just for the viewport. And not necessarily a modification of the one I linked, but something that works similarly. $\endgroup$
    – Tech Crate
    Jan 23 at 18:43

2 Answers 2

5
$\begingroup$

What to Do

You can do this in Python with a loop, but what you loop on depends on what materials you want to change. The key is that eventually you want to set material.blend_method = 'OPAQUE' and the problem becomes how you pick material.

If, for instance, you wanted to change the mode for every material:

for material in bpy.data.materials:
        material.blend_method = 'OPAQUE'

Or you might want to change the mode for the active object:

object = bpy.context.active_object
for slot in object.material_slots:
    if slot.material:
        slot.material.blend_method = 'OPAQUE'

or if you wanted to change the mode on the selected objects, you would use the loop in this answer

How to Do it

There are two easy ways you can go about doing this.

  1. Interactive:
    • Open a Python Console window and paste the code directly into the window.
  2. As a text:
    • Open a text editor
    • click 'New' to create a new text
    • Insert the line import bpy
    • Paste the text
    • Click the run button (looks like the 'play' button in the time line.

The first approach is immediate. The second takes a little more time, but then you can save the text as a Python file and load it again later.

$\endgroup$
5
$\begingroup$

Affects all selected objects

for ob in bpy.context.selected_objects:
    for slot in ob.material_slots:
        if slot.material:
            slot.material.blend_method = 'OPAQUE'
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.