1
$\begingroup$

I have a set of tools that I use with blender and wanted to know how can I pre-import this module into blender's python console and have it accessible all the time. Just like how bpy works and I don't need to import every time I'm opening the program.

$\endgroup$
1
$\begingroup$

At startup, Blender reads the contents of the scripts/startup/ directory for python modules and imports them. You can also choose to use scripts as add-ons (turn on/off via Add-Ons manager):

http://www.blender.org/api/blender_python_api_2_73_release/info_overview.html

$\endgroup$
  • $\begingroup$ I think I wasn't clear enough. So I have this module that I don't want to copy into blender's folders as add-on or startup script. I'm trying to write Another startup script or addon that basically tells blender console to "import mymodule as MM" and have it available when I'm working in console. is that possible at all? $\endgroup$ – Ehsan Irannejad Mar 10 '15 at 17:04
0
$\begingroup$

Around line 97 in scripts\modules\console_python.py, there is some code regarding the imports / convenience variables:

    namespace["__builtins__"] = sys.modules["builtins"]
    namespace["bpy"] = bpy

    # weak! - but highly convenient
    namespace["C"] = bpy.context
    namespace["D"] = bpy.data

It doesn't work however if you add import bmesh; namespace["bmesh"] = bmesh here.

Maybe this code isn't really used, you might wanna check the C code.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.