7
$\begingroup$

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: enter image description here

And have the value show up automatically on this text object, without any type of manual refresh: enter image description here

$\endgroup$
  • $\begingroup$ Please add clarity to your SEBB Question ... by including some screen shots, relevant images, and annotations. Please include a written question with a [?] as the first line of your entry. People here can help you more with a question written by you and you may refine your question later. There are tags below your entry. Did you create the tags? $\endgroup$ – atomicbezierslinger Jun 2 '15 at 0:56
  • $\begingroup$ I'll clean it up a bit. "Please include a written question with a [?] as the first line of your entry." Why? I know it's a bit unclear, but why is this necisary? "People here can help you more with a question written by you and you may refine your question later." What exactly is this supposed to mean? That people can edit my post? I know that! My last chunk of rep came from editing someones post! "There are tags below your entry. Did you create the tags?", No one has edited my post, did I create the tags? Sorry, any rudeness, but your comment came across as rude and offensive to me. $\endgroup$ – TARDIS Maker Jun 2 '15 at 2:09
  • $\begingroup$ Just edited. Hopefully this helps. $\endgroup$ – TARDIS Maker Jun 2 '15 at 2:25
  • 2
    $\begingroup$ I am thrilled by your new and improved problem statement. $\endgroup$ – atomicbezierslinger Jun 2 '15 at 2:41
  • $\begingroup$ Sorry about how bad the other one was. I really didn't notice how bad it was until you commented. $\endgroup$ – TARDIS Maker Jun 2 '15 at 4:37
6
$\begingroup$

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.

  1. create an empty
  2. create a driver on the x transform (not too important which axis)
  3. run script in text editor.
  4. set up driver

Code:

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.

enter image description here

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.

enter image description here

$\endgroup$
  • $\begingroup$ Okay, neat! I'm going to try this out tomorrow. If it works, I'll accept it (looks pretty functional to me). It's possible also that with the new deps graph, the fake driver won't be necessary. I'm going to have to download a buildbot build. $\endgroup$ – TARDIS Maker Jun 2 '15 at 6:04
  • $\begingroup$ Seems to half work in the .blend you provided. The driver didn't update automatically. I had to update it manually. $\endgroup$ – TARDIS Maker Jun 2 '15 at 6:18
  • $\begingroup$ just checked that and have updated answer to include "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." $\endgroup$ – wardrums Jun 2 '15 at 6:38
  • $\begingroup$ Still doesn't work. I hope you understand that I want it to change when the samples value changes which it currently doesn't. $\endgroup$ – TARDIS Maker Jun 2 '15 at 6:51
  • $\begingroup$ should have mentioned the driver is activated when you change frame $\endgroup$ – wardrums Jun 2 '15 at 7:29
5
$\begingroup$

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.

  1. Choose your text object and create new Object Custom Property, name this "Samples" (or any you wish). Ensure that you set default number with no decimals.
  2. Then add driver for this Property. Choose "Manually Create Later (Single)".
  3. Open F-Curve panel in Driver mode, find your driver and setup it like on the screenshot below:

    enter image description here

  4. Now create new Animation Nodes NodeTree:

    Animation Nodes NodeTree

You even can just create scripted Subprogram:

It will be more clearly and faster.

enter image description here

$\endgroup$
  • $\begingroup$ Just in case anyone wants to rebuild this, the Debug Node is now called "Viewer" Node. $\endgroup$ – Ben Jan 28 at 10:35
-3
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ Can you patch this up a bit please. $\endgroup$ – iKlsR Jun 2 '15 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.