3
$\begingroup$

enter image description here
I know that the content of text can be registered through a user-defined function and entered in the Expressions box. But how can I use text as a data block for variables, as shown in the image? Blender's UI allows such manipulation, so I just wondered how to use it.

enter image description here
Of course, Transform Channel, Rotational Differences, Distance were not available in the text. Single Property seemed possible.

enter image description here
but when I checked my text through bpy.data.texts['Text'].keys(), by default, the text did not have any properties.

enter image description here
I tried this.

enter image description here
And it worked but I do not think it's a very useful use.

enter image description here
Blender also allows you to use many other types of data blocks as variables in the driver, other than text. This may mean a lot of freedom to writing a driver, but I've never seen cases that uses data blocks other than objects or armature as variables for the driver.

If you know any good ideas or examples, please share them with me. Thank you.

$\endgroup$
4
  • $\begingroup$ Hello, for information what is your end goal with this feature ? $\endgroup$
    – Gorgious
    Commented Oct 20, 2020 at 14:58
  • $\begingroup$ Yes, there is no clear goal, but I would like to understand more about how to use the blender driver variable. $\endgroup$ Commented Oct 20, 2020 at 15:03
  • $\begingroup$ Then could you rephrase your question so it is more focused ? I'd very much like to help you but I can't pinpoint what you are asking for $\endgroup$
    – Gorgious
    Commented Oct 20, 2020 at 15:18
  • $\begingroup$ I'd like to know various examples of making drivers using more different types of data. I revised the title to reveal my intention a little more. $\endgroup$ Commented Oct 20, 2020 at 16:18

1 Answer 1

8
$\begingroup$

Make a test driver script to see what works what doesn't.

Using textblock as a driver variable target was going to be an other suggestion re your question on bringing in a text datablock when linking.

Re Text blocks

Speculatively at issue here is drivers use evaluated scene objects, and text objects don't get evaluated... a custom prop may not update in the driver if animated.

>>> eto = D.texts['Text'].evaluated_get(C.evaluated_depsgraph_get())
>>> eto
bpy.data.texts['Text']

>>> eto.is_evaluated
False

A simple test driver

To fiddle about with drivers I often make use of this little test script

  • Use use_self to pass the evaluated object. \

  • Can pass all driver variables as as locals()

Generic test script.

import bpy

def test(*args, **kwargs):
    for arg in args:
        print(arg)
        
    return -1 # a simple val to indicate working

bpy.app.driver_namespace["test"] = test

Now set up a driver and test the test.

enter image description here

The driver is on object "Circle", the text object evaluates to None as do most. However the matrix world of the cube object is passed. As is the depsgraph the driver is using to evaluate the objects.

<bpy_struct, Object("Circle") at 0x7f1cb1372e08, evaluated>
{'text': None, 'var': Matrix(((1.0, 0.0, 0.0, 0.0),
        (0.0, 1.0, 0.0, 0.0),
        (0.0, 0.0, 1.0, 0.0),
        (0.0, 0.0, 0.0, 1.0))), 'depsgraph': <bpy_struct, Depsgraph at 0x7f1cbeb80108>}

enter image description here Adding a rotate driver on cube, the console shows updates the values for both viewing and rendering animation

Now from the matrix world it appears we have all the transforms of the Cube object in our driver in one fell swoop.

The ideology of a driver is to return an int or float as the value of the driven property. Will find however can make this driver a "pseudo" copy transform constraint by adding before the return statement and re-running driver.

args[0].matrix_world = args[1]['var']

which using better names is self.matrix_world = cube.matrix_world If say the x location is being driven by this, then it is given that value and all others are taken from the matrix world.. This is abuse of the driver system .. but hey it's fun.

Some answers using drivers

This one adds drivers to drive material index of each face of a mesh https://blender.stackexchange.com/a/183716/15543

$\endgroup$
2
  • $\begingroup$ Amazing insight. The idea of a driver, the test of what works, is what I wanted to hear. The driver variable fields are so open that beginners like me are puzzled. But now I realize that many data types are not given a clear use, but rather use depending on a user's ingenuity. $\endgroup$ Commented Oct 20, 2020 at 16:25
  • 1
    $\begingroup$ A great lesson in how to get under the bonnet. :) $\endgroup$
    – Robin Betts
    Commented Oct 20, 2020 at 16:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .