# How to use different types of data blocks for driver variables?

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.

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

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

I tried this.

And it worked but I do not think it's a very useful use.

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.

• Hello, for information what is your end goal with this feature ? Oct 20 '20 at 14:58
• Yes, there is no clear goal, but I would like to understand more about how to use the blender driver variable. Oct 20 '20 at 15:03
• 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 Oct 20 '20 at 15:18
• 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. Oct 20 '20 at 16:18

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.

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>}


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.