I’m trying to integrate a UIList into a custom node but I’m faced with a problem I can’t find a solution to.
When I add my custom nodes to the material node editor, the UILists are “linked”. I mean, if I scroll in the uilist of my node, all the uilists scroll at the same time.
Same if I enlarge the uilist window on one of the nodes. This also affects all other nodes with this UIList.
How to make each UIList unique to each node ?
Here is a test code to see what it is.
import bpy
import nodeitems_utils
from bpy.types import Node, UIList
class Custom_UL_items(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
layout.label(item.name)
class TreeNodeValidity:
@classmethod
def poll(cls, ntree):
return ntree.bl_idname == 'ShaderNodeTree'
class CustomUIListNode(Node, TreeNodeValidity):
bl_idname = 'UIListNode'
bl_label = 'UIList Node'
def init (self, context):
self.outputs.new('NodeSocketColor', "RGB")
self.outputs["RGB"].default_value = (0.8, 0.8, 0.8, 1.0)
def update(self):
print("updated")
def draw_buttons(self, context, layout):
rows = 3
layout.template_list("Custom_UL_items", "", bpy.context.object,
"material_slots",
bpy.context.object, "active_material_index",
rows=rows
)
class CustomUIListNodeNodeCategory(nodeitems_utils.NodeCategory):
@classmethod
def poll(cls, context):
return context.space_data.tree_type == 'ShaderNodeTree'
node_categories = [
CustomUIListNodeNodeCategory("SOMENODE", "UIList Node", items=[
nodeitems_utils.NodeItem("UIListNode"),
]),
]
classes = [
Custom_UL_items,
CustomUIListNode
]
def register():
for cls in classes:
bpy.utils.register_class(cls)
nodeitems_utils.register_node_categories("CUSTOM_NODE", node_categories)
def unregister():
nodeitems_utils.unregister_node_categories("CUSTOM_NODE")
for cls in classes:
bpy.utils.unregister_class(cls)
if __name__ == "__main__":
register()