I am trying to create a simple library of procedural materials for myself.

As per my logic what I need to do is :

  1. Create a node tree in Python
  2. For preview purposes I think I will add a Data-block/New Material for the material the user has chosen and when the user changes the material just clear the previously generated material
  3. I succeeded in creating a material preview but I have not tried it with a python generated material and the major fallback is that I need to resize the preview window to refresh the preview
  4. I know that I can use tempelate_ID_preview but :
    1. It updates in at least 5 seconds.
    2. It has a bunch of unnecessary 'UI' stuff with it

My Code :

import bpy

class TESTMATPANEL(bpy.types.Panel):
    bl_idname = "panelname"
    bl_label = "Panelname"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Testing"

    def poll(cls, context):
        ntree = context.space_data.node_tree
        return ntree is not None and ntree.type=='SHADER'

    def draw(self, context):
        layout = self.layout

        row = layout.row()
        ob = context.active_object
        self.layout.template_preview(ob.active_material, show_buttons= False)

def register():


def unregister():


if __name__ == "__main__":

My method of creating a procedural Material(Nodes will be different) :


All I need to know is :

  1. How to detect the change in the material and to redraw the preview
  2. How to link the temporary material to the template_preview
  3. Pls help me

! I know that my 'Class' naming is wrong, it was just a test attempt so I didn't pay much attention


Your Answer

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

Browse other questions tagged or ask your own question.