1

I'm trying to edit the Sun position addon (that's bundled with Blender). Normally the addon work by detecting Environnement Texture nodes, and then letting you pick which one to use, but I found out it doesn't detect the node if it's a custom group. So I'm trying to change that I (think) found the line in the script that detect the Env node normally:

    if context.scene.world is not None:
        if context.scene.world.node_tree is not None:
            col.prop_search(sp, "hdr_texture", context.scene.world.node_tree, "nodes", text="")
        else:
            col.label(text="Please activate Use Nodes in the World panel.",
                      icon="ERROR")
    else:
        col.label(text="Please select World in the World panel.",
                  icon="ERROR")

col is the UI box, and sp is the sun position info And I think I need something like this:

    if context.scene.world is not None:
        if context.scene.world.node_tree is not None:
            col.prop_search(sp, "hdr_texture", context.scene.world.node_tree, "nodes", text="")
        if code-to-get-node-groups is not None:
            code-to-get-the-nodes-for-each-group


    else:
        col.label(text="Please activate Use Nodes in the World panel.",
                  icon="ERROR")
else:
    col.label(text="Please select World in the World panel.",
              icon="ERROR")

But the thing is I don't know how to access custom groups, or the nodes inside said groups I tried looking it up, but my knowledge of python is pretty basic, so I'm a bit stuck.

Can anyone tell me if:

the logic is sound? and if it is, how do I access those groups and their nodes?

thanks in advance!

  • A node group is basically a node containing another node tree. You access it by retrieving the node group node, then assuming it's a node tree : nodes["Group"].node_tree.nodes – Gorgious Aug 27 '21 at 08:49
  • @Gorgious Yeah I tried that before but I got an error message saying the nodes["Group"] didn't exist, so I thought I needed to first declare a variable or something? But maybe I didn't write it right at all in the first place. Do I need to write just nodes["Group"].nodes["Group"].node_tree.nodes or do I need the full context.scene.world.node_tree.nodes["Group"].node_tree.nodes? (or even something else?) – Felina Faerlaingal Aug 27 '21 at 09:09
  • Well I tried some more, but I ended giving up. I kept getting errors that I didn't understand, and then on top of that I realised the Sun Position addon doesn't do what I thought it did. (I thought it moved the Sun from the HDRI value, but it does the opposite). I solved my problem with multiple drivers instead. It's longer to setup than a button push but at least it works and I know what I'm doing. Thanks anyway – Felina Faerlaingal Aug 27 '21 at 10:09

0 Answers0