3

For example:

bpy.data.textures["mouth shapes"].image_user.frame_offset = bpy.data.objects["rigMeenuTeen"].pose.bones["eyes"].location

Can this kind of expression be a driver?

ashwin
  • 1,739
  • 2
  • 21
  • 46

1 Answers1

4

If the property doesn't allow for drivers, it cannot be driven with a driver.

It can be driven through app.handlers though:

import bpy

def my_handler(scene):
    # this code will be run on every frame change
    loc = bpy.data.objects["rigMeenuTeen"].pose.bones["eyes"].location
    bpy.data.textures["mouth shapes"].image_user.frame_offset = int(loc.x)

bpy.app.handlers.frame_change_pre.append(my_handler)
Jaroslav Jerryno Novotny
  • 51,077
  • 7
  • 129
  • 218
  • thanks. "frame_change_post" is not updating in 3D viewport. But "frame_change_pre" is updating and working fine. Non-scripted drivers updating update even interactively (i mean when i move driver around with mouse it affects driven) is that possible in scripted way? – ashwin May 06 '15 at 03:46
  • @ashwin Fixed the answer to '_pre' handler. Can you specify what you mean with the last question? Classic drivers cannot update (call) events, but PyDrivers could. I am not sure if that is what you were asking.. – Jaroslav Jerryno Novotny May 06 '15 at 06:07
  • i mean when i add driver through right click and specify driver details in driver window. Then that driver affects the driven even when its moved with mouse. But this scripted driver only affects when we play the animation. Or is ther "on_mouse_move" handler available like "frame_change_pre" ? – ashwin May 06 '15 at 06:22
  • @ashwin no, there isn't 'on_mouse_move' but there is 'scene_update' which basically runs all the time. Executing a function there might slow down blender a lot so if you really must the best is to setup a monitor for that property like this: http://blender.stackexchange.com/questions/19668/execute-a-python-function-whenever-the-user-interacts-with-the-program. Instead of a name you can watch a bone's position and update the frame_offset accordingly – Jaroslav Jerryno Novotny May 06 '15 at 06:48