Meta Scriptid 01
print(sub-title)
Decided to have a go and see what I could do with scripting in blender, the above is a cube grid array thing of randomly sized meta-balls, the material is also controlled by the script.
Not every run of the script created an interesting arrangement, so multiple runs were needed to get an interesting arrangement, multiple runs though would add new objects and materials on each run (eventually causing a crash).
To avoid this happening lines 5 through 10 were added to clear down any materials and objects from the previous run, this also clears the default cube, camera and light from the scene if you’re config file still includes them
Lines 13 to 15 set up the dimensions for the ‘cube’ array
The below section of code is a modified version of the code shown by dr. Sybren A. Stüvel On Scripting for Artists , which instead of 300 monkeys generates a grid of 20 meta balls.
This initial array from the first bit of code is then duplicated and these duplicates are stacked on top of each other (the number of stacks controlled by the height variable), inside the while loop the code also assigns the properties to the meta balls, including a random radius for each meta ball. The numbers would (do) work without being multiplied but create very small objects (at least with my default config settings) so the multiplication is just to make the meta balls a bit larger.
All the created meta ball objects in the scene are then looped through and their object names, 'Mball', 'Mball.001' and so on are appended to the 'created' list for use later.
These next blocks of code set up the material that will be used. The first bit just creates the material name and tells it to use nodes for the setup, it then clears away any previous existing nodes. Next the nodes that I want to use are created and if needed their default values can be changed (though I wasn't able to work out how to add an additional colour stop to the colour ramp node). The nodes are then linked together and given a position in the node window, the positions are an optional step to lay the nodes out nicely if they need to be viewed.
Finally each of the meta balls is called by name and the material is assigned to it, for mesh objects it's possible to assign different materials to the objects, but this didn't seem to want to work with meta balls.