Would like to be able to change the material node displayed in the
Node Editor from Python after running an operator to create a new material node in Python. In the
Node Editor, I can click "New" and have a new node created and displayed (see the image below). I can also select which material to display. Is there a way to do this from Python?
I am linking the material from another
.blend file and would like to display the new material in the editor so the user can immediately start working on it. The new material node is not linked to any object by default, that is left up to the user. The code looks like this:
with bpy.data.libraries.load(blend) as (data_from, data_to):
data_to.materials = ['fancy material']
# Change the Node editor display to show the new node?
While trying to figure out how to change the displayed material node, I found this code that displays the
template_ID but do not know how to change it display my new material nodes. (Edited for brevity)
bl_space_type = 'NODE_EDITOR'
def draw(self, context):
snode = context.space_data
# Custom node tree is edited as independent ID block
layout.template_ID(snode, "node_tree", new="node.new_node_tree")
Realizing this isn't the best "blender" behavior, is it possible?