I have tried it earlier but I can only find a way to change the color space of a single image texture node using python so, I want to ask if there's a way to change it for separate image texture nodes?


1 Answer 1

import bpy

def change_color_space(object, color_space='sRGB'):
    Change the color space of all the image texture node.
    object (bpy.types.Object) - The object to take material from.
    color_space (enum in [‘Filmic Log’, ‘Filmic sRGB’, ‘Linear’, ‘Linear ACES’, ‘Linear ACEScg’, ‘Non-Color’, ‘Raw’, ‘sRGB’, ‘XYZ’], default ‘sRGB’) - Color space in the image file, to convert to and from when saving and loading the image.
    if object.material_slots:
        for slot in object.material_slots:
            if slot.material:
                node_tree = slot.material.node_tree

                for node in node_tree.nodes:
                    if node.type == 'TEX_IMAGE' and node.image:
                        node.image.colorspace_settings.name = color_space
change_color_space(bpy.context.object, 'Non-Color')
  • $\begingroup$ Thank you so much! Also, I had two more questions:- 1. Can you suggest as code for changing the color spaces of particularly the image textures attached to albedo/base color of the Principled BSDF of all materials? 2. Is there a code through which I can remove the image textures attached to Alpha of Principled BSDF of all materials? $\endgroup$
    – Manwire06
    Commented Oct 2, 2022 at 4:37
  • $\begingroup$ Learn some blender API $\endgroup$
    – Karan
    Commented Oct 2, 2022 at 10:56

You must log in to answer this question.

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