Page 1 of 1

Accessing Node Properties using Python?

Posted: Fri Nov 23, 2018 9:04 pm
by Lights_and_Shadows
I remember in the old LuxRender we could access the specific nodes using Luxrender-specific keywords. Is that still possible? I've been attempting to change colors using a script and so far I've had no success.

Re: Accessing Node Properties using Python?

Posted: Fri Nov 23, 2018 9:09 pm
by B.Y.O.B.
Yes it's perfectly possible.
What exactly do you want to do?

Re: Accessing Node Properties using Python?

Posted: Fri Nov 23, 2018 9:15 pm
by Lights_and_Shadows
I have a series of Mix nodes for RGB colors, about 9 in total - a group of 8, four of which are for diffuse, the other four for specular highlights. The last one is for emission. I know how to do it for Cycles no issues, but I don't know how to point to LuxCore specifically. All I am trying to do is take the "Color 2" RGB values from each of those nodes, and replace them with another value, but doing it from a script instead of in the Node Editor itself. It's so I can have some form of color preset, if you will.

Re: Accessing Node Properties using Python?

Posted: Fri Nov 23, 2018 9:29 pm
by B.Y.O.B.
It's actually very similar to Cycles nodes.
Just that to access the node tree, you have to call material.luxcore.node_tree.
If you want to change a socket value, get the socket from node.inputs, then call its default_value attribute (it holds the value of the socket when no node is linked to it).

I hope the example image helps. Also the console is a big help to explore this interactively.
If you have further questions, feel free to ask.

Re: Accessing Node Properties using Python?

Posted: Fri Nov 23, 2018 9:44 pm
by Lights_and_Shadows
Ahh, that was all I needed. Thanks, B.Y.O.B :) I know where to go from here. It now sees my nodes.

Re: Accessing Node Properties using Python?

Posted: Fri Nov 23, 2018 9:55 pm
by B.Y.O.B.
In case you want to iterate over all nodes in a tree by type, look into the nodes folder in the addon.
for example, the material node types:
https://github.com/LuxCoreRender/BlendL ... t__.py#L10

So you can do stuff like

Code: Select all

for node in node_tree.nodes:
    if node.bl_idname == "LuxCoreNodeMatMix":
        ... # Do stuff with all mix material nodes