Node To Python

NodeToPython logo

Overview

Node To Python (Github, Blender Extension Platform) is a Blender extension I created to turn node groups into Python scripts and standalone add-ons for recreating them. It supports all node tree types within Blender: geometry nodes, object materials, compositing nodes, and misc. shaders. Especially if you need custom functionality or to modify a node group dynamically, Node To Python is a great way to automatically get Python code for creating it.

The README is a pretty good overview of how to use the project. The rest of this post will be more geared towards the development of NodeToPython, written as it stands in v4.1

Project Structure

The codebase contains two directories of note:

  1. tools/ contains some scripts for helping with the development of NodeToPython. Since NodeToPython is a tool to help artists and programmers make tools, tools/ contains the tools to make the tool that makes tools (I currently have no plans for recursing further)
    1. node_settings_generator/parse_nodes.py scrapes the Blender documentation to find out the structure of each node in each Blender version, compiling all nodes and settings into a dictionary to be used while exporting. Updating this dictionary was previously a manual and error-prone process, and now new Blender versions are much easier to integrate
    2. package.py is a simple script to generate the extension’s .zip. I’d often forget to remove the pycache directories on release, so it’s nice to have this automated now
  2. NodeToPython/ is the extension itself. It’s divided into two parts:
    1. ui/ contains the code for drawing the UI elements, selecting settings, and adding node groups for export. The code’s not particularly interesting, but the UX has come a long way over the last four years. You used to have to push a button hidden away under the Object menu and type in the name of the node group you wanted to export. This is still evolving and ever-improving as I get feedback and suggestions from users
    2. export/ is where the bulk of the logic resides. We’ll dive in a little deeper in the next section

How NodeToPython exports a node tree

Developer Environment Setup and Practices