Maniphest T96292

Unable to set active material output node using Python
Closed, Resolved

Assigned To
Jacques Lucke (JacquesLucke)
Authored By
Greg Zaal (gregzaal)
Mar 10 2022, 12:32 PM
Tags
  • BF Blender
  • Python API
  • Nodes & Physics
Subscribers
Greg Zaal (gregzaal)
Jacques Lucke (JacquesLucke)
Philipp Oeser (lichtwerk)
Pratik Borhade (PratikPB2123)

Description

System Information
Operating system: Windows-10-10.0.19044-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 2080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 497.29

Blender Version
Broken: version: 3.1.0, branch: master, commit date: 2022-03-08 18:16, hash: rBc77597cd0e15
Worked: 3.0

This changed in rB7e712b2d6a0d: Nodes: refactor node tree update handling

Short description of error
It seems to be (inconsistently) no longer possible to set the world/shader node tree's active output using python.

Running node.is_active_output = True in a fresh scene does anything. But if you (in the UI) click on one of the output nodes, setting it as the active output, then from that point onwards doing node.is_active_output = True will indeed work.

Exact steps for others to reproduce the error

  1. Starting from factory defaults
  2. In a python console editor, run: node = C.scene.world.node_tree.nodes.new('ShaderNodeOutputWorld') to create a new world output node. This node is named World Output.001. The original output node is named World Output.
  3. Check the current state of the active output node:
  4. C.scene.world.node_tree.nodes['World Output'].is_active_output - the result is True as this is the original node.
  5. C.scene.world.node_tree.nodes['World Output.001'].is_active_output - the result is False as this is the new node.
  6. Try set the new node as active output using C.scene.world.node_tree.nodes['World Output.001'].is_active_output = True. Nothing happens, the value remains False even after we set it.
  7. In the UI, click on the newly created node, setting it as the active output (verify this with the code above if needed, is_active_output is now True for the new node)
  8. Click on the original node to set that as the active output.
  9. Run C.scene.world.node_tree.nodes['World Output.001'].is_active_output = True again, this time it successfully changes the tree's active output to that node.

As a side note, is there some other workaround way I can consistently set the node tree's active output? I need to fix an add-on and can't wait for this to be patched.

Revisions and Commits

rB Blender
D14301
D14301

Related Objects

Mentioned In
T96241: 3.1: Potential candidates for corrective releases
T96396: is_active_output stopped working correctly
Mentioned Here
rB7e712b2d6a0d: Nodes: refactor node tree update handling

Event Timeline

Greg Zaal (gregzaal) created this task.Mar 10 2022, 12:32 PM
Philipp Oeser (lichtwerk) updated the task description.Mar 10 2022, 12:56 PM
Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Confirmed.Mar 10 2022, 1:06 PM
Philipp Oeser (lichtwerk) added a subscriber: Philipp Oeser (lichtwerk).

Can confirm (to some extend).
In 3.0, it was possible to have 2 active outputs at the same time, setting World Output.001 active did not set World Output inactive (this was wrong, too).
There has probably been some fix that does not allow for that anymore (otoh, it did not take into account that this prevents setting it active from python in some situations), will check

Pratik Borhade (PratikPB2123) added projects: Python API, Nodes & Physics.Mar 10 2022, 2:42 PM
Pratik Borhade (PratikPB2123) added a subscriber: Pratik Borhade (PratikPB2123).
Greg Zaal (gregzaal) added a comment.Mar 10 2022, 2:47 PM

I guess ideally we have some node_tree.set_active_output_node function in the API, and not have to rely on the python code having to make sure to set all outputs to False except one.

I saw there was also a node_tree.active_output property, but this was always -1 and didn't seem writable.

Philipp Oeser (lichtwerk) added a comment.Mar 10 2022, 4:18 PM

This changed in rB7e712b2d6a0d: Nodes: refactor node tree update handling btw.

Philipp Oeser (lichtwerk) updated the task description.Mar 10 2022, 4:19 PM
Philipp Oeser (lichtwerk) triaged this task as High priority.Mar 10 2022, 4:23 PM
Philipp Oeser (lichtwerk) added a subscriber: Jacques Lucke (JacquesLucke).

Even though this was not quite right in 3.0 either, will still set this to High prio (since now it seems this is not possible to set at all).

@Jacques Lucke (JacquesLucke): opinions?

Jacques Lucke (JacquesLucke) claimed this task.Mar 10 2022, 5:40 PM
Jacques Lucke (JacquesLucke) added a revision: D14301: Fix T96292: Unable to set active material output using Python..

I saw there was also a node_tree.active_output property, but this was always -1 and didn't seem writable.

Think that's the index of the active output socket in a node group.


The fix seems to be to make the other outputs of the same type inactive.

Jacques Lucke (JacquesLucke) added a comment.Mar 10 2022, 5:45 PM

FYI, bug reports that require the python console are sometimes a bit annoying, because I have to type/copy so much every time I want to reproduce it. Usually I end up preparing myself a file that just has a small script in it that I can just run to reproduce the bug. It doesn't matter too much, but if you happen to report similar bugs in the future, maybe consider writing a small(!) script instead of using the console.

E.g. this is the script I used for this bug:

import bpy

n1 = bpy.context.scene.world.node_tree.nodes['World Output']
n2 = bpy.context.scene.world.node_tree.nodes['World Output.001']

n1.is_active_output = True
n2.is_active_output = True

print(n1.is_active_output, n2.is_active_output)
Jacques Lucke (JacquesLucke) closed this task as Resolved by committing rB22a341d9d8d3: Fix T96292: unable to set active material output using Python.Mar 10 2022, 6:04 PM
Jacques Lucke (JacquesLucke) added a commit: rB22a341d9d8d3: Fix T96292: unable to set active material output using Python.
Pratik Borhade (PratikPB2123) mentioned this in T96396: is_active_output stopped working correctly.Mar 14 2022, 5:54 AM
Philipp Oeser (lichtwerk) added a commit: rB40cbbe809c0a: Fix T96292: unable to set active material output using Python.Mar 21 2022, 2:07 PM