3

Is there a way to convert nodes (or nodes group) into Python script automatically?

If not what is the python script to:

  • create a node and set his position
  • attach a node to another and choose the input and output (and found the name of the input/output script)
  • create a group
  • choose if we want to create the node in the compositor or for a cycles shader
  • mute a node
Danyl Bekhoucha
  • 3,722
  • 13
  • 47
  • 96
  • related: http://blender.stackexchange.com/questions/5668/add-nodes-to-material-with-python – TLousky Jun 16 '16 at 15:30
  • 2
    I would say that each of those bullet points should be separate questions, some of which have already been answered on the site. – Ray Mairlot Jun 16 '16 at 15:31
  • 2
    All the answers are here: http://blender.stackexchange.com/questions/23436/control-cycles-material-nodes-and-material-properties-in-python/23446 (for Cycles nodes) and here: http://blender.stackexchange.com/questions/19500/controling-compositor-by-python/19501 (for Compositor nodes). You mute a node by toggling it's node.mute property. Please read the python API documentation. – Jaroslav Jerryno Novotny Jun 17 '16 at 05:42
  • Shader node group is just enother node type of ShaderNodeGroup and you access it's nodes like this: node.node_tree.nodes (through it's own node_tree property). Here is the documentation: https://www.blender.org/api/blender_python_api_2_77_1/bpy.types.ShaderNodeGroup.html#bpy.types.ShaderNodeGroup – Jaroslav Jerryno Novotny Jun 17 '16 at 05:47
  • You can also use Python nodes as in here: https://blender.stackexchange.com/questions/67487/cycles-materials-math-node-with-more-than-two-inputs/99003/ – Secrop Nov 05 '18 at 10:33

2 Answers2

3

There's not an out-of-the-box, native way to do this, at least as of the current version (Blender 3.6). However, you can write a script using the Python API.

As for a solution that does all this automatically, I've created an open source add-on that does all this for Geometry Nodes and Shader Nodes for Blender 3.0-3.6, with work in progress for Compositing Nodes.

https://github.com/BrendanParmer/NodeToPython

  • You're right, I was trying to futureproof the response in case something were to change after v3.6. As far as I'm aware this hasn't ever been a feature that comes with Blender – BrendanParmer Aug 03 '23 at 02:44
  • Alright, all good then. Thank you for the answer and the addon. Congrats for the 100 stars ! ;) – Gorgious Aug 03 '23 at 09:52
-1

Here is a repo that does exactly what you want. It has a ready-to-run python script that can be run from the command line in the background without opening the blender GUI. It creates a water material on a surface mesh for a convecting bubble - this is done with 2 different shaders and mixing them using a mixer shader. The script loops through the different files and renders the images as jpeg. The images are also there in the repo. Just clone the repo and run the command given in the README file in the terminal. This scripting was done with Blender v2.78.

https://github.com/nataraj2/BlenderScripting