As a textblock
One way to do this is to add functions.py
as a Text block. Make sure the Text block has a .py
extension and you can import it directly using import functions
. Described here: python-is-it-possible-to-import-another-text-block
As a module
Otherwise, add functions.py
to scripts/modules/some_name/functions.py
, then
from some_name import functions
A slight hack
There's probably an elegant way to do this, but if your stuck...
The render.py could load functions.py
from a given path into a text block named the same:
# render.py #
import bpy
fp = '/home/zeffii/Desktop/functions.py'
def make_functions_local(fp):
texts = bpy.data.texts
t = texts.get('functions.py')
if not t:
t = texts.new('functions.py')
with open(fp) as module_file:
t.from_string(module_file.read())
# trigger it
make_functions_local(fp)
import functions
# your stuff