I have imported many images as planes and need to change the texture interpolation from linear to closest to solve an issue similar to this one: Transparent image planes in cycles have strange borders (although I am on eevee).

enter image description here

This could be done with python right?


1 Answer 1


You would have to find all image texture nodes and set their interpolation type to 'Closest':

import bpy

# Run through all materials of the current blend file
for mat in bpy.data.materials:
    # If the material has a node tree
    if mat.node_tree:
        # Run through all nodes
        for node in mat.node_tree.nodes:
            # If the node type is texture 
            if node.type == 'TEX_IMAGE':
                # Set the interpolation -> Linear, Closest, Cubic, Smart
                node.interpolation = 'Closest' 

See: https://docs.blender.org/api/current/bpy.types.ShaderNodeTexImage.html#bpy.types.ShaderNodeTexImage.interpolation

  • $\begingroup$ I got this error: ``` Traceback (most recent call last): File "/home/farid/Gunga/Nature Brasil/animation/cenas1-2-3-4-5.blend/Text", line 4, in <module> AttributeError: 'NoneType' object has no attribute 'nodes' Error: Python script failed, check the message in the system console ``` $\endgroup$ Commented Nov 18, 2020 at 21:42
  • 1
    $\begingroup$ yes, if there are no nodes, the script will fail... add another for loop after for mat in bpy.data.materials: if mat.use_nodes == True: . $\endgroup$
    – susu
    Commented Nov 18, 2020 at 22:35
  • 1
    $\begingroup$ See also: blender.stackexchange.com/a/181959/92768 $\endgroup$
    – susu
    Commented Nov 18, 2020 at 22:37
  • 1
    $\begingroup$ @brockmann thanks for the edit! $\endgroup$
    – susu
    Commented Nov 19, 2020 at 15:19
  • 1
    $\begingroup$ No problem @FaridAbdelnour Glad you got it working... Yeah, I'd recommend to communicate at least, we are all just volunteers trying to help each other. $\endgroup$
    – brockmann
    Commented Nov 25, 2020 at 12:50

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