How to register custom math function? I need to create a script to define certain math functions. This script will not directly modify or create any objects. I will simply use them with the XYZ Math surface and/or the Z Math surface. Among other functions, I need a sgn() function (why on Earth it isn't part of python I cannot fathom) and an a^b function that can handle non-integer b for negative a.

Creating these functions isn't a problem. I already have, for use with drivers, and I know I need to register them there by

bpy.app.driver_namespace['&lt;functionname&gt;'] = &lt;functionname&gt;


But how and where do I register them to be able to use them. My guess would be

bpy.app.foo['&lt;functionname&gt;'] = &lt;functionname&gt;


But what should I substitute for foo here?

This is simply amazing. I've googled for days about this, and the answer is nowhere to be found. Everything is about modifying meshes and creating classes to extend blender's functionality with new addons.. I have no need for that. I may at a later time, but I don't know. Is there really no way to implement a standalone mathematical function and register it in a way that it's available to all aspects of the program?
You first example line bpy.app.driver_namespace['&lt;functionname&gt;'] = &lt;functionname&gt; registers the function within the driver namespace and makes it available as &lt;functionname&gt; within any driver expressions.

From other areas of blender you can access it with it's full data path - bpy.app.driver_namespace['&lt;functionname&gt;'](3) calls that function passing a value of 3.

But that isn't the issue you have with the math object creation -

The XYZ math surface object allows you to enter an arbitrary string to define the surface of the object. As this also allows any python to be run it implements a security feature that prevents any functions not listed in it's safe_list from being run.

To get around this you need to do two steps, add your functions as a module and then import them into the addon and add the names to the safe list. Or you can adjust the usage of the safe list to allow any functions. You may want to duplicate the addon and adjust it so you have your own custom addon that suites your needs. You may also find it easier to define the calculations used and just input a few variables.

For a sign function in a on-line script you can use 1 if x&gt;0 else 0

For a^b I don't see an issue -2**3.5 returns -11.31370849898476