Accessing Node Properties using Python?

Use this forum for general user support and related questions.
Post Reply
User avatar
Lights_and_Shadows
Posts: 25
Joined: Thu Jan 18, 2018 3:40 pm
Location: United States

Accessing Node Properties using Python?

Post by Lights_and_Shadows » Fri Nov 23, 2018 9:04 pm

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.
Windows 7 Professional, x64
Intel Core i7 6700K, 4GHz
EVGA GeForce GT740 Superclocked, 4GB GDDR5
32GB RAM DDR4 (approx. 80GB with pagefile active)
RAID 0 configured HDD setup (2x 500GB Seagate Barracudas)

User avatar
B.Y.O.B.
Developer
Posts: 1816
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Accessing Node Properties using Python?

Post by B.Y.O.B. » Fri Nov 23, 2018 9:09 pm

Yes it's perfectly possible.
What exactly do you want to do?
Support LuxCoreRender project with salts and bounties

User avatar
Lights_and_Shadows
Posts: 25
Joined: Thu Jan 18, 2018 3:40 pm
Location: United States

Re: Accessing Node Properties using Python?

Post by Lights_and_Shadows » Fri Nov 23, 2018 9:15 pm

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.
Windows 7 Professional, x64
Intel Core i7 6700K, 4GHz
EVGA GeForce GT740 Superclocked, 4GB GDDR5
32GB RAM DDR4 (approx. 80GB with pagefile active)
RAID 0 configured HDD setup (2x 500GB Seagate Barracudas)

User avatar
B.Y.O.B.
Developer
Posts: 1816
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Accessing Node Properties using Python?

Post by B.Y.O.B. » Fri Nov 23, 2018 9:29 pm

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.
Attachments
2018-11-23_22-27-44.png
Support LuxCoreRender project with salts and bounties

User avatar
Lights_and_Shadows
Posts: 25
Joined: Thu Jan 18, 2018 3:40 pm
Location: United States

Re: Accessing Node Properties using Python?

Post by Lights_and_Shadows » Fri Nov 23, 2018 9:44 pm

Ahh, that was all I needed. Thanks, B.Y.O.B :) I know where to go from here. It now sees my nodes.
Windows 7 Professional, x64
Intel Core i7 6700K, 4GHz
EVGA GeForce GT740 Superclocked, 4GB GDDR5
32GB RAM DDR4 (approx. 80GB with pagefile active)
RAID 0 configured HDD setup (2x 500GB Seagate Barracudas)

User avatar
B.Y.O.B.
Developer
Posts: 1816
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: Accessing Node Properties using Python?

Post by B.Y.O.B. » Fri Nov 23, 2018 9:55 pm

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
Support LuxCoreRender project with salts and bounties

Post Reply