2
$\begingroup$

I'm importing hundreds of different textures into Blender and I want to change the blend mode on all of them from Alpha Blend to Opaque. I understand I will need to run a python command, however the ones I have tried do not work. Help would be appreciated

Edit: here are 2 of the scripts I have tried running--

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

the first one gives me this error:

  File "<blender_console>", line 4
    for material in bpy.data.materials:
IndentationError: expected an indented block after 'for' statement on line 3

Here's the 2nd one that I tried

object = bpy.context.active_object
for slot in object.material_slots:
    if slot.material:
        slot.material.blend_method = 'OPAQUE'
$\endgroup$
2
  • $\begingroup$ Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Please provide the script that didn't work. $\endgroup$ Nov 5, 2023 at 23:37
  • $\begingroup$ @RumenBelev I have posted the scripts, although it seems like the first one should work. I'm not sure why it doesn't. $\endgroup$
    – David
    Nov 5, 2023 at 23:57

1 Answer 1

2
$\begingroup$

Indentation is important when interpreting the script. You have two tabs on the first script and it is supposed to be a single tab indentation. Also Blender developers recommend using 4 spaces as indentation instead of tabs (although both variants work): Try copying and running the script bellow:

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

The second script also works. Make sure to include the line

import bpy

at the beginning of each script.

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

Link to Best Practice https://docs.blender.org/api/current/info_best_practice.html

$\endgroup$
1
  • $\begingroup$ This works! Thank you so much for your help $\endgroup$
    – David
    Nov 6, 2023 at 0:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .