Improving Load Textures
Nodes can be moved to a different position by setting the x
and y
attributes of their location
property. This allows us to arrange them in our scripts.
Arranging shader nodes
Even if we can move our nodes freely, the API poses a few limitations:
- We can’t access the exact location of the sockets
- The width and height of new nodes are not available in the scripts
One of those two issues at a time would be tolerable, as we could either move our nodes at the height of their inputs or get the space required by a new node on the fly. Since they occur together, we will resort to a workaround.
Assuming node spacing
We cannot get the size of new nodes in a script, but we can learn the default size of a texture node beforehand by looking at an existing shader tree. For instance, after we use Load Texture, we can switch to the Scripting workspace and get the dimensions
property of an 'Image
Texture'
node:
>>> node_tree...