Skip to main content
added 61 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

The driver namespace

Can add functions and constants to the driver namespace

import bpy

def func(a, b, c):
    return a * b * c

m = 9.4443299912

bpy.app.driver_namespace["f"] = func
bpy.app.driver_namespace["m"] = m

Run the script above to, (copy & paste into text editor hit Run Script button,) to make the new members available to the driver namespace. To make it autorun when file is loaded, give the text block a py extension and check the Register checkbox on RHS of text editor header

enter image description here

Can now consider m in a driver expression to be a named constant like pi and e.

Use in a driver expression like f(m, m, m) Can be typed directly into a field by preceding with a hash # character. Once the expression is a driver (purple) on editing expression there is no longer a need for #.

enter image description here

There are a number of functions and properties etc already defined to the namespace, a sample of python console output.

>>> for k, v in bpy.app.driver_namespace.items():
...     k, v
...     
('asin', <built-in function asin>)
('asinh', <built-in function asinh>)
('atan', <built-in function atan>)
...
('pi', 3.141592653589793)
('e', 2.718281828459045)
...
('f', <function func at 0x7f8f18d34c80>)
('m', 9.4443299912)
('frame', 1.0)

Where frame is the context.scene.frame_current.

EDIT: would like to see a "sub expression" driver variable type where you could do this for scalars, or using other defined variables. Fitting everything into the scripted expression can be a PITA.

The driver namespace

Can add functions and constants to the driver namespace

import bpy

def func(a, b, c):
    return a * b * c

m = 9.4443299912

bpy.app.driver_namespace["f"] = func
bpy.app.driver_namespace["m"] = m

Run the script above to make the new members available to the driver namespace. To make it autorun when file is loaded, give the text block a py extension and check the Register checkbox on RHS of text editor header

enter image description here

Can now consider m in a driver expression to be a named constant like pi and e.

Use in a driver expression like f(m, m, m) Can be typed directly into a field by preceding with a hash # character. Once the expression is a driver (purple) on editing expression there is no longer a need for #.

enter image description here

There are a number of functions and properties etc already defined to the namespace, a sample of python console output.

>>> for k, v in bpy.app.driver_namespace.items():
...     k, v
...     
('asin', <built-in function asin>)
('asinh', <built-in function asinh>)
('atan', <built-in function atan>)
...
('pi', 3.141592653589793)
('e', 2.718281828459045)
...
('f', <function func at 0x7f8f18d34c80>)
('m', 9.4443299912)
('frame', 1.0)

Where frame is the context.scene.frame_current.

EDIT: would like to see a "sub expression" driver variable type where you could do this for scalars, or using other defined variables. Fitting everything into the scripted expression can be a PITA.

The driver namespace

Can add functions and constants to the driver namespace

import bpy

def func(a, b, c):
    return a * b * c

m = 9.4443299912

bpy.app.driver_namespace["f"] = func
bpy.app.driver_namespace["m"] = m

Run the script above, (copy & paste into text editor hit Run Script button,) to make the new members available to the driver namespace. To make it autorun when file is loaded, give the text block a py extension and check the Register checkbox on RHS of text editor header

enter image description here

Can now consider m in a driver expression to be a named constant like pi and e.

Use in a driver expression like f(m, m, m) Can be typed directly into a field by preceding with a hash # character. Once the expression is a driver (purple) on editing expression there is no longer a need for #.

enter image description here

There are a number of functions and properties etc already defined to the namespace, a sample of python console output.

>>> for k, v in bpy.app.driver_namespace.items():
...     k, v
...     
('asin', <built-in function asin>)
('asinh', <built-in function asinh>)
('atan', <built-in function atan>)
...
('pi', 3.141592653589793)
('e', 2.718281828459045)
...
('f', <function func at 0x7f8f18d34c80>)
('m', 9.4443299912)
('frame', 1.0)

Where frame is the context.scene.frame_current.

EDIT: would like to see a "sub expression" driver variable type where you could do this for scalars, or using other defined variables. Fitting everything into the scripted expression can be a PITA.

added 310 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

The driver namespace

Can add functions and constants to the driver namespace

import bpy

def func(a, b, c):
    return a * b * c

m = 9.4443299912

bpy.app.driver_namespace["f"] = func
bpy.app.driver_namespace["m"] = m

Run the script above to make the new members available to the driver namespace. To make it autorun when file is loaded, give the text block a py extension and check the Register checkbox on RHS of text editor header

enter image description here

Can now consider m in a driver expression to be a named constant like pi and e.

Use in a driver expression like f(m, m, m) Can be typed directly into a field by preceding with a hash # character. Once the expression is a driver (purple) on editing expression there is no longer a need for #.

enter image description here

There are a number of functions and properties etc already defined to the namespace, a sample of python console output.

>>> for k, v in bpy.app.driver_namespace.items():
...     k, v
...     
('asin', <built-in function asin>)
('asinh', <built-in function asinh>)
('atan', <built-in function atan>)
...
('pi', 3.141592653589793)
('e', 2.718281828459045)
...
('f', <function func at 0x7f8f18d34c80>)
('m', 9.4443299912)
('frame', 1.0)

Where frame is the context.scene.frame_current.

EDIT: would like to see a "sub expression" driver variable type where you could do this for scalars, or using other defined variables. Fitting everything into the scripted expression can be a PITA.

The driver namespace

Can add functions and constants to the driver namespace

import bpy

def func(a, b, c):
    return a * b * c

m = 9.4443299912

bpy.app.driver_namespace["f"] = func
bpy.app.driver_namespace["m"] = m

Can now consider m in a driver expression to be a named constant like pi and e.

Use in a driver expression like f(m, m, m) Can be typed directly into a field by preceding with a hash # character. Once the expression is a driver (purple) on editing expression there is no longer a need for #.

enter image description here

There are a number of functions and properties etc already defined to the namespace, a sample of python console output.

>>> for k, v in bpy.app.driver_namespace.items():
...     k, v
...     
('asin', <built-in function asin>)
('asinh', <built-in function asinh>)
('atan', <built-in function atan>)
...
('pi', 3.141592653589793)
('e', 2.718281828459045)
...
('f', <function func at 0x7f8f18d34c80>)
('m', 9.4443299912)
('frame', 1.0)

Where frame is the context.scene.frame_current.

EDIT: would like to see a "sub expression" driver variable type where you could do this for scalars, or using other defined variables. Fitting everything into the scripted expression can be a PITA.

The driver namespace

Can add functions and constants to the driver namespace

import bpy

def func(a, b, c):
    return a * b * c

m = 9.4443299912

bpy.app.driver_namespace["f"] = func
bpy.app.driver_namespace["m"] = m

Run the script above to make the new members available to the driver namespace. To make it autorun when file is loaded, give the text block a py extension and check the Register checkbox on RHS of text editor header

enter image description here

Can now consider m in a driver expression to be a named constant like pi and e.

Use in a driver expression like f(m, m, m) Can be typed directly into a field by preceding with a hash # character. Once the expression is a driver (purple) on editing expression there is no longer a need for #.

enter image description here

There are a number of functions and properties etc already defined to the namespace, a sample of python console output.

>>> for k, v in bpy.app.driver_namespace.items():
...     k, v
...     
('asin', <built-in function asin>)
('asinh', <built-in function asinh>)
('atan', <built-in function atan>)
...
('pi', 3.141592653589793)
('e', 2.718281828459045)
...
('f', <function func at 0x7f8f18d34c80>)
('m', 9.4443299912)
('frame', 1.0)

Where frame is the context.scene.frame_current.

EDIT: would like to see a "sub expression" driver variable type where you could do this for scalars, or using other defined variables. Fitting everything into the scripted expression can be a PITA.

added 169 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244

The driver namespace

Can add functions and propertiesconstants to the driver namespace

import bpy

def func(a, b, c):
    return a * b * c

m = 9.4443299912

bpy.app.driver_namespace["f"] = func
bpy.app.driver_namespace["m"] = m

ThenCan now consider m in a driver can use an expression to be a named constant like pi and e.

Use in a driver expression like f(m, m, m) Which canCan be typed directly into a field by preceding with a hash # character. Once the expression is a driver (purple) on editing expression there is no longer a need for #.

enter image description here

There are a number of functions and properties etc already defined to the namespace, a sample of python console output.

>>> for k, v in bpy.app.driver_namespace.items():
...     k, v
...     
('asin', <built-in function asin>)
('asinh', <built-in function asinh>)
('atan', <built-in function atan>)
...
('pi', 3.141592653589793)
('e', 2.718281828459045)
...
('f', <function func at 0x7f8f18d34c80>)
('m', 9.4443299912)
('frame', 1.0)

Where frame is the context.scene.frame_current.

EDIT: would like to see a "sub expression" driver variable type where you could do this for scalars, or using other defined variables. Fitting everything into the scripted expression can be a PITA.

The driver namespace

Can add functions and properties to the driver namespace

import bpy

def func(a, b, c):
    return a * b * c

m = 9.4443299912

bpy.app.driver_namespace["f"] = func
bpy.app.driver_namespace["m"] = m

Then in a driver can use an expression like f(m, m, m) Which can be typed directly into a field by preceding with a hash # character.

enter image description here

There are a number of functions and properties etc already defined to the namespace, a sample of python console output.

>>> for k, v in bpy.app.driver_namespace.items():
...     k, v
...     
('asin', <built-in function asin>)
('asinh', <built-in function asinh>)
('atan', <built-in function atan>)
...
('pi', 3.141592653589793)
('e', 2.718281828459045)
...
('f', <function func at 0x7f8f18d34c80>)
('m', 9.4443299912)
('frame', 1.0)

Where frame is the context.scene.frame_current.

EDIT: would like to see a "sub expression" driver variable type where you could do this for scalars, or using other defined variables. Fitting everything into the scripted expression can be a PITA.

The driver namespace

Can add functions and constants to the driver namespace

import bpy

def func(a, b, c):
    return a * b * c

m = 9.4443299912

bpy.app.driver_namespace["f"] = func
bpy.app.driver_namespace["m"] = m

Can now consider m in a driver expression to be a named constant like pi and e.

Use in a driver expression like f(m, m, m) Can be typed directly into a field by preceding with a hash # character. Once the expression is a driver (purple) on editing expression there is no longer a need for #.

enter image description here

There are a number of functions and properties etc already defined to the namespace, a sample of python console output.

>>> for k, v in bpy.app.driver_namespace.items():
...     k, v
...     
('asin', <built-in function asin>)
('asinh', <built-in function asinh>)
('atan', <built-in function atan>)
...
('pi', 3.141592653589793)
('e', 2.718281828459045)
...
('f', <function func at 0x7f8f18d34c80>)
('m', 9.4443299912)
('frame', 1.0)

Where frame is the context.scene.frame_current.

EDIT: would like to see a "sub expression" driver variable type where you could do this for scalars, or using other defined variables. Fitting everything into the scripted expression can be a PITA.

added 144 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244
Loading
added 469 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244
Loading
added 4 characters in body
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244
Loading
Source Link
batFINGER
  • 85.2k
  • 10
  • 114
  • 244
Loading