Shape key python script

Hey!
I’m making a character with shape keys. I’m makin a shape for the mouth where my char smiles. I now got two shapekeys. leftSmile and rightSmile.
I’ve then made a plane and a circle and parented the circle to the plane. The circle is at 0,0 (Look at this). The bottom line means that my char isn’t smiling but havin a normal look. when the circle is at the top in the middle both shape keys should go to 1. When at the top left the rightSmile should be at 1 and leftSmile at 0. But is this doable as one python line?
Here can u see what i mean bout the smiles. Hope you understand what i mean.

I can PHP and if it was made with PHP the script would look like this(The values are the value of the circle):

<?php
if($xValue > 1){
  $lValue = 1;
}
$rValue = 2 - $xValue;
if($rValue > 1){
  $rValue = 1;
}
$rValue = -($lValue-1); //The -() makes the value of $rValue possitiv
$upValue = $yValue / 2;
$finalValue = $upValue * $sideValue;
?>

I thought bout making it like Bassam but i would rather like to have a 0 rotation on all axis and have to plane to be 2 * 2 blender units.

Best regards
Mariolink

Doesn’t have to fit on one line.

Create a text in the text editor called ‘pydrivers.py’

Then add a function e.g. ;


import Blender
from Blender import *

def myfunc():
  ob=Object.Get("circleControl")
  obX = ob.LocX
  obZ = ob.LocZ
  obY = ob.LocY
 ....
 ....
 ....
  return value

Your code can go in almost unchanged :

  • remove the ‘$’ for the variables

  • remove the ‘{’ for “if” blocks (Python uses indentation, i.e. whitespace, DON’T mix TABS and SPACES (TABS are preferred and the Blender text editor uses TABS by default

  • add a “:” at the end of your if blocks

Mike

Then in the pydriver put :

p.myfunc()

(“p” is automatically imported as an alias for ‘pydrivers’).

More info on the Wiki http://mediawiki.blender.org/index.php/BlenderDev/PyDrivers

Mike

Kewl thanks.

Now to figure out how to code it properly :slight_smile:

EDIT: Question. Does it update just like if I had an object to be the driver and every time I moved it it would update?
EDIT2: It does update. Thanks for the help Mike :smiley: