1
$\begingroup$

I've working on "private" exporter and it has some issues like the topic. The addon perfectly working inside latest Blender 3.6.5 but did not worked with 4.0a and 4.1a. Here the part of codes:

def getOutputNode(material):
    node = None
    if material.use_nodes and material.cout.use_nodes and material.node_tree:
        node_tree = material.node_tree
        if node_tree.active_output != -1 and node_tree.nodes[node_tree.active_output].bl_idname == "COutputNode":
            node = node_tree.nodes[node_tree.active_output]
        if not node:
            for n in node_tree.nodes:
                if n.bl_idname == "COutputNode" and n.is_active_output:
                    node = n
    return node

def findCOutputNode(material):
    node = None
    if material.node_tree:
        node_tree = material.node_tree
        if node_tree.active_output != -1 and \
            node_tree.nodes[node_tree.active_output].bl_idname == "COutputNode":
            node = node_tree.nodes[node_tree.active_output]
        if not node:
            for n in node_tree.nodes:
                if n.bl_idname == "COutputNode":
                    node = n
    return node

and here that error:

    if node_tree.active_output != -1 and node_tree.nodes[node_tree.active_output].bl_idname == "COutputNode":

AttributeError: 'ShaderNodeTree' object has no attribute 'active_output'

$\endgroup$

1 Answer 1

2
$\begingroup$

The Blender Node Tree structure has changed in 4.0. So, no longer are inputs or outputs accessed through NodeTree.inputs or NodeTree.outputs but by iterating over NodeTree.interface.items_tree. Getting the active_item can be found through NodeTree.interface.active but it is not targeted to inputs or outputs. It will be harder to get the active input or output due to the API changes. For more detail, visit 4.0 Node Group Python API

    for item in tree.interface.items_tree:
        if item.item_type == 'SOCKET':
            if item.in_out == 'INPUT':
                ...
            elif item.in_out == 'OUTPUT':
$\endgroup$
5
  • $\begingroup$ Where am I must change this lines? ' for item in tree.interface.items_tree: if item.item_type == 'SOCKET': if item.in_out == 'INPUT': ... elif item.in_out == 'OUTPUT': ' $\endgroup$ Oct 11, 2023 at 16:17
  • $\begingroup$ Substitute tree in tree.interface.items_tree with the tree you are working on. You can make a function to find the output closest to the active item if the active item is not an output. $\endgroup$ Oct 11, 2023 at 16:42
  • 1
    $\begingroup$ I'm a bit stumped that the new API is so much more complicated than the previous one... I understand that it opens up a lot of possibilites UI wise to have subpanels in the in/outputs but it makes the entry barrier for newbies much higher... $\endgroup$
    – Gorgious
    Oct 11, 2023 at 18:21
  • $\begingroup$ I totally agree with you. For panels, they should have just added a 'Panels' ui list and make them accessible through tree.inputs, tree.outputs, or tree.panels. However, I'm not a Dev and they may have better reasons to do it the way they did it, $\endgroup$ Oct 11, 2023 at 18:54
  • $\begingroup$ Guys, please, help me! I don't understand which am I must to do and which lines are need to change? $\endgroup$ Oct 27, 2023 at 15:41

You must log in to answer this question.

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