# what is scripted expression syntax

**URL:** <https://blenderartists.org/t/what-is-scripted-expression-syntax/526624>\
**Category:** Python Support\
**Created:** [December 8, 2011, 2:36am UTC](https://blenderartists.org/t/what-is-scripted-expression-syntax/526624 "2011-12-08T02:36:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![huggaida](https://blenderartists.org/user_avatar/blenderartists.org/huggaida/32/17705_2.png) [@huggaida](https://blenderartists.org/u/huggaida)\
**Post date:** [December 8, 2011, 2:36am UTC](https://blenderartists.org/t/what-is-scripted-expression-syntax/526624/1 "2011-12-08T02:36:14Z")

</div>

So i want to use drivers with option “scripted expression”? for example typing “frame” in var field gives me my propertie equal current frame. If i want for example cube1 locX be equal cube2 rotZ? what is syntaxis. I tryed wiki’s :

_math.pi \* 2 + 5.0_

Blender.Get(“curframe”) # the current animation frame

math.sin(Blender.Get(“curframe”)) # the sine of the current frame

self.LocX \* 10

but non of this dos not work for me with 2.6  
Please help!

---

<div class="post-metadata">

**Author:** ![test-dr](https://blenderartists.org/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@test-dr](https://blenderartists.org/u/test-dr)\
**Post date:** [December 8, 2011, 4:47am UTC](https://blenderartists.org/t/what-is-scripted-expression-syntax/526624/2 "2011-12-08T04:47:14Z")

</div>

> [@huggaida"](#):
>
> So i want to use drivers with option “scripted expression”? for example typing “frame” in var field gives me my propertie equal current frame. If i want for example cube1 locX be equal cube2 rotZ? what is syntaxis. I tryed wiki’s :
> 
> _math.pi \* 2 + 5.0_
> 
>  
> 
> Blender.Get(“curframe”) # the current animation frame
> 
> math.sin(Blender.Get(“curframe”)) # the sine of the current frame
> 
> _self.LocX \* 10_
> 
> but non of this dos not work for me with 2.6  
> Please help!

to set cube1 locx to the rotation of cube2 rotZ  
enter for  
the driver of cube1-locx (insert a single-driver … switch to fcurves-\>drivers)  
a variable (±sign)  
and select as object: cube2  
and as part the transform: rotation-Z-axis  
(check you have the right rotation-mode … XYZ-Euler … and not quaternions…)

then enter into the expression field:  
var

press return, maybe enable debug to view the current values …  
… you know the rotations are in radians …?

for conversion to degrees, just use  
var\*360/pi

---

<div class="post-metadata">

**Author:** ![batFINGER](https://blenderartists.org/user_avatar/blenderartists.org/batfinger/32/5981_2.png) [@batFINGER](https://blenderartists.org/u/batFINGER)\
**Post date:** [December 8, 2011, 7:29am UTC](https://blenderartists.org/t/what-is-scripted-expression-syntax/526624/3 "2011-12-08T07:29:44Z")

</div>

frame was only a recent and handy addition. For

math.sin(Blender.Get(“curframe”)) # the sine of the current frame

you can type

#sin(frame)

straight into the property as shown here.

> **[GSoC11 - An easy way to create expressions...](http://aligorith.blogspot.nl/2011/07/gsoc11-easy-way-to-create-expressions.html)**
>
> In case you missed my commit the other day , I've recently committed a new feature which makes it easier to set up "expressions". Exp...

Using driver variables in expressions

> **[Driver "Variables" - Why they exist](http://aligorith.blogspot.nl/2011/09/driver-variables-why-they-exist.html)**
>
> I'm aware that there has been a bit of angst among some users of the driver system in 2.5 over the need to define "variables" for drivers to...

custom functions for driver expressions.

> **[\[Rigging FAQ\] Addedum Info on Drivers System](http://aligorith.blogspot.nl/2011/01/rigging-faq-addedum-info-on-drivers.html)**
>
> Re-reading my earlier post on the Drivers system , I realised that I overlooked mentioning a few things that I had intended to mention. Also...

explanation of transform space

> **[GSoC11 - "Local Space" for Transform Channel Drivers Rebooted](http://aligorith.blogspot.nl/2011/06/gsoc11-local-space-for-transform.html)**
>
> After much lobbying (in the form of countless bug reports and feature requests all over the place), I've taken a second look at the situatio...

run down of the driver system (some features have changed)

> **[\[Rigging FAQ\] Basics of the New Driver System in 2.5](http://aligorith.blogspot.nl/2010/09/rigging-faq-basics-of-new-driver-system.html)**
>
> Monitoring bug reports over the past while, I have noticed that there appear to be some misconceptions about the Driver system in 2.5. As us...

test-dr… whoops mate… 2pi radians = 360 degrees… anyway why not use the maths functions

radians(deg)

or

degrees(rad)

---

<div class="post-metadata">

**Author:** ![test-dr](https://blenderartists.org/letter_avatar_proxy/v4/letter/t/d07c76/32.png) [@test-dr](https://blenderartists.org/u/test-dr)\
**Post date:** [December 8, 2011, 10:02am UTC](https://blenderartists.org/t/what-is-scripted-expression-syntax/526624/4 "2011-12-08T10:02:35Z")

</div>

> [@batFINGER](#):
>
> frame was only a recent and handy addition. For
> 
> math.sin(Blender.Get(“curframe”)) # the sine of the current frame  
> …  
> …
> 
> test-dr… whoops mate… 2pi radians = 360 degrees… anyway why not use the maths functions
> 
> radians(deg)
> 
> or
> 
> degrees(rad)

lol, yep! batFINGER, you are totally righty right.  
I have some braindamage from my setting for the cyclic wobbling  
of some very important body-parts - and those body-parts  
dont wobble/jiggle in the full cycle of one walk-animation/run-animation,  
they have only half of the cycle of the base-animation.

---

<div class="post-metadata">

**Author:** ![huggaida](https://blenderartists.org/user_avatar/blenderartists.org/huggaida/32/17705_2.png) [@huggaida](https://blenderartists.org/u/huggaida)\
**Post date:** [December 8, 2011, 8:41pm UTC](https://blenderartists.org/t/what-is-scripted-expression-syntax/526624/5 "2011-12-08T20:41:52Z")

</div>

thank’s a lot. Amazing functionality!!!

---

<div class="post-metadata">

**Author:** ![wigglyboots](https://blenderartists.org/letter_avatar_proxy/v4/letter/w/d2c977/32.png) [@wigglyboots](https://blenderartists.org/u/wigglyboots)\
**Post date:** [February 12, 2012, 2:54pm UTC](https://blenderartists.org/t/what-is-scripted-expression-syntax/526624/6 "2012-02-12T14:54:31Z")

</div>

I understand how to set up scripted expressions using the gui, but how exactly do you set a Scripted Expression using python?

Edit:

Ah, I figured it out. For anyone else wondering, this is how you set a driver’s expression with python, assuming you are setting the very first driver element in the driver list:

```auto
bpy.data.objects['rig'].animation_data.drivers[0].driver.expression = 'expression goes here'

```
