How can I drive the content of a text object by a value box such as the samples slider?
I want to be able to change the value here:
And have the value show up automatically on this text object, without any type of manual refresh:
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It only takes a minute to sign up.Sign up to join this community
i have created a blend example to show how to do this. http://www.pasteall.org/blend/36360
Ill warn you that this is big hack. it will most likley not work if you submit this job to an external renderfarm, deppending on the renderfarm settings.
What we want to do is create a driver on a transform property of an unrelated empty. Then write a custom Python Driver that updates the Text.body string with the Scene.cycles.samples value.
import bpy def update_driver(): bpy.data.objects['Text'].data.body = "%i samples" %bpy.context.scene.cycles.samples return 0 bpy.app.driver_namespace["update_driver"] = update_driver
Run this code when you open the file. now our custom pydriver will be available in the expression field of the driver. If you have already entered the expression before running the script, you will need to click in the expression field, and press enter to update.
It is important to have this fake_driver variable connected to a transform property of an object. This 'hack' forces the driver to update on each frame. In the driver we now enter update_driver() for the expression.
Depending on your settings, you may need to open the User preferences and turn on 'auto run python scripts' to allow our python driver to work.
I will show how you can achieve such result with Animation Nodes Add-on:
Unfortunately AN doesn't work with Drivers directly (at the moment, actual version 1.6.0), but can read/write attributes of other objects. That's why this solution could seems strange on first look.
Open F-Curve panel in Driver mode, find your driver and setup it like on the screenshot below:
Now create new Animation Nodes NodeTree:
It will be more clearly and faster.
consider the python script pseudo excerpt
def somefunctionName(): object.data.body = textcreated //use one only ... good to know about the pair bpy.app.handlers.frame_change_pre.append(somefunctionname) //bpy.app.handlers.frame_change_post.append(somefunctionname) //to have a function called on every frame render
You may also have to remove any previously append-ed function or reload Blender.
The appends can accumulate if you are furiously updating your python
You can search at this site for many examples.