4
$\begingroup$

I've found some people mention that almost any blender value can have the magic value "#frame" to use the current frame number as the value.

for example, change an object's X location to '#frame/100" and it will rapidly fly away when walking through the frames.

What I'm looking for, is a list of available # (hashtags) that can be used in this manner, like #end_frame

I found this section in the documentaion, but it seems incomplete, I swear I've seen people use other values here beyond was listed in the docs:

https://docs.blender.org/manual/en/latest/animation/drivers/usage.html#expression

$\endgroup$
3

2 Answers 2

5
$\begingroup$

The other answer is perfectly valid although I would have added a list of the builtin available namespace functions :

print([k for k in bpy.app.driver_namespace.keys()])

>> 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 
'cos', 'cosh', 'degrees', 'dist', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 
'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'isclose', 
'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log1p', 
'log10', 'log2', 'modf', 'pow', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 
'tan', 'tanh', 'trunc', 'prod', 'perm', 'comb', 'nextafter', 'ulp', 'pi', 'e', 
'tau', 'inf', 'nan', 'bpy', 'noise', 'clamp', 'lerp', 'smoothstep'

Additionnally you can access a list of "builtin" keys with

print([k for k in bpy.app.driver_namespace["__builtins__"]])

>> 'abs', 'all', 'any', 'ascii', 'bin', 'breakpoint', 'callable', 'chr', 'compile', 
'delattr', 'dir', 'divmod', 'eval', 'exec', 'format', 'getattr', 'globals', 
'hasattr', 'hash', 'hex', 'id', 'input', 'isinstance', 'issubclass', 'iter', 
'aiter', 'len', 'locals', 'max', 'min', 'next', 'anext', 'oct', 'ord', 'pow', 
'print', 'repr', 'round', 'setattr', 'sorted', 'sum', 'vars', 'None', 'Ellipsis', 
'NotImplemented', 'False', 'True', 'bool', 'memoryview', 'bytearray', 'bytes', 
'classmethod', 'complex', 'dict', 'enumerate', 'filter', 'float', 'frozenset', 
'property', 'int', 'list', 'map', 'object', 'range', 'reversed', 'set', 'slice', 
'staticmethod', 'str', 'super', 'tuple', 'type', 'zip', '__debug__',
'BaseException', 'Exception', 'TypeError', 'StopAsyncIteration', 'StopIteration',
'GeneratorExit', 'SystemExit', 'KeyboardInterrupt', 'ImportError', 'ModuleNotFoundError', 
'OSError', 'EnvironmentError', 'IOError', 'WindowsError', 'EOFError', 'RuntimeError', 
'RecursionError', 'NotImplementedError', 'NameError', 'UnboundLocalError', 
'AttributeError', 'SyntaxError', 'IndentationError', 'TabError', 'LookupError', 
'IndexError', 'KeyError', 'ValueError', 'UnicodeError', 'UnicodeEncodeError', 
'UnicodeDecodeError', 'UnicodeTranslateError', 'AssertionError', 'ArithmeticError', 
'FloatingPointError', 'OverflowError', 'ZeroDivisionError', 'SystemError', 
'ReferenceError', 'MemoryError', 'BufferError', 'Warning', 'UserWarning', 
'EncodingWarning', 'DeprecationWarning', 'PendingDeprecationWarning',
'SyntaxWarning', 'RuntimeWarning', 'FutureWarning', 'ImportWarning', 'UnicodeWarning', 
'BytesWarning', 'ResourceWarning', 'ConnectionError', 'BlockingIOError', 
'BrokenPipeError', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionRefusedError', 
'ConnectionResetError', 'FileExistsError', 'FileNotFoundError', 'IsADirectoryError', 
'NotADirectoryError', 'InterruptedError', 'PermissionError', 'ProcessLookupError', 
'TimeoutError', 'open', 'quit', 'exit', 'copyright', 'credits', 'license', 'help'

Note some of these functions don't return a number-compatible value (string, or custom classes) so I wouldn't advise trying to use them.

WARNING: Since it's a mini Python interpreter you risk inadvertently causing side effects. For example try typing quit() in a driver expression field (save your file first) :)

There is also a list of hardcoded functions (Source) : 'bool', 'float', 'int', 'clamp', 'lerp', 'smoothstep".

It seems there are three additional special cases,

  • 'frame' which returns the current frame. Source
  • 'self' which returns the evaluated object. Source
  • 'depsgraph' which can be used to retrieve data from the current context. Source

I would also add that the title and body of the question are misleading. You make the assumption that # grants access to the list of driver namespace functions, but the purpose of writing # in a property field is to automatically setup a driver. It saves you a few clicks you need to manually setup a driver :

  • Right click in the field
  • Add Driver
  • Then in the popup delete the variable
  • Write the driver expression in the field

For example you can write #min(2,cos(2)) or #2 to setup drivers. These two concepts (# and namespace functions) are independant of each other.

$\endgroup$
7
  • $\begingroup$ but "frame" is not in the list. Do you know why or how to get the list with "frame" included (and eventually others)? $\endgroup$
    – lemon
    Commented Jan 13 at 8:27
  • $\begingroup$ @lemon great question. I updated the answer. In addition to the builtins there is bool, float, int, clamp, smoothstep, lerp. Also there are two special cases, frame and self. I don't think there is any other hardcoded keys. $\endgroup$
    – Gorgious
    Commented Jan 13 at 9:01
  • $\begingroup$ The reason why IMO is because vanilla namespace keys are directly imported from the python math and mathutils module, while others are treated as special cases $\endgroup$
    – Gorgious
    Commented Jan 13 at 9:04
  • $\begingroup$ Gorgious, thanks a lot. It seems there is 'depsgraph' also github.com/blender/blender/blob/… ... just to complete the list! $\endgroup$
    – lemon
    Commented Jan 13 at 9:06
  • $\begingroup$ @lemon Ah, yes missed that one ! Cheers $\endgroup$
    – Gorgious
    Commented Jan 13 at 9:08
3
$\begingroup$

list the currently loaded names with the blender scripting console attrbiute bpy.app.driver_namespace, this is a python dictionary who's keys are valid "python expression" variable names in Driver Scripted Expressions

we can see the functions available to us, and our current frame

>>> bpy.app.driver_namespace.keys()
dict_keys([..., 'acos', 'acosh', 'asin', 'asinh', ...])
>>> bpy.app.driver_namespace['frame']
1
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .