I would like to add a distance driver to a materiel emission node using python. I have tried several things to no avail, can someone please give me some guidance.
As the Suzanne object move along the path, i want the distance between Suzanne and one of the bulbs to control the emission strength
Not sure of the python way, but it sounds like this could be done with texture coordinate - object > gradient - spherical in terms of cycles nodes. (And a few converter math nodes to adjust things.) Somebody who knows scripting may show up knowing the equivalent.
I can create a driver to control emission strength by hand. See base object (“Bulb”) in blend file. It works fine, i just want to duplicate this driver for all the new objects created using python.
If I recall correctly, you would have to dig into data-blocks for the material via the outliner to set drivers for materials. (Look for something like “node tree, shader node tree”, and go from there.) A bit tedious, compared to the expected way of using the nodes on the compositor interface. However you can keep the compositor nodes displayed while hunting through the outliner tree heirarchy, since when you find the right one it’s values will change with the setting in the outliner. Also don’t forget about the search function in the outliner, since that can help narrow things down.
I consider it an odd annoying quirky way of doing things, but it does work if you really need drivers on materials.
I tried using texture coord object with linked object. Unfortunately this doesn’t update correctly for lights when I move things around; if I want to update the output I have to reselect the object in the dropdown. If this updated correctly (or you can force an update), you only need to figure out the distance between the linked coordinate and the lights geometry position.
Ermmm… Maybe something like this material applied to the light spheres?
I tried it the way I mentioned earlier, but the spherical falloff aspect was too obvious. This vector math way seems to do it as a level over the entire object.
Now how to build it through a script… Somebody else will have to cover that part.