How to load scripts that have been "Make Internal"ed?


Im using the ogremeshexporter script. Usually it needs me to add /ogrepkg into the .blender/scripts directory wherever blender is installed.

That directory/package is then loaded by main script by passing it a directory (eg: “~~~.blender/scripts/ogrepkg”.

This however adds the exporter to all blender files, as it becomes part of the default menu. Instead I want to load it only in the one file ( well multple files, but all will be "Save As…"ed from teh one file.).

I’ve opened all the /ogrepkg .py files into the Blender Text editor and made them internal. Now I’m asking how I can set a registry key that will reference the internal scripts. ( as in the “from Blender import Registry” Registry).

I’m new to blender scripting, but not to blender or python. I think what I’m looking for is a function in the API that tells me the current blender filename, from there I should be able to construct that directory string to the internal scripts yes?
name = Blender.getCurrerntFileName()
reg = {}
reg[0] = name + “scripts/”
… etc loading the scripts into the dictionary
Registry.setKey(“OgrePackage”, reg)

Then from there I know that It will load them fine ( because the backup way of checking where to load from is to check the Registry else prompt for a file. When It prompts for a file, I can only select the .blend file, I cannot “delve deeper” into the .blend file…

Thanks for any help. I’m not sure if I’ve described it properly, but hopefully youll get the idea.

I have an “Internal-ed” script I need to get out too. Anybody know how to get them back out?

I’m not exactly sure that I understand what you want to do but all internalized texts are in and can be indexed by name (buffer name that is, NOT filename). Now there is no permanent record of the current Blender filename (that I know off, Blender.Get(‘filename’) will only get you the last file read or written), but if all you need is to use an internalized text as a module, you could do something like this (warning untested code):

import bpy
import sys
import MyModule

Because you can access the text, in principle you could use the exec statement, but then you have to think about where newly defined names end up or you could write your own import mechanism using but all that is quite involved.


Couldn’t you just select ‘Text->Save As’ or isn’t that what you mean?

@pig, I couldn’t find any text. There was one said text file in the text editor, but it was empty. The script is functioning so I know it’s there. But when I’m in the text editor it says the text is “Internal”.

could it be that the default empty textbuffer is selected in the editor and the script you are talking about is just not selected (It is easily overlooked after all)? You can select that other file (if its there) with the text drop down in the editor:

Perhaps, you can use the settings of “Scripts” directory to solve the issue… It is located in the INFORMATION panel (marked with “i” and placed ABOVE your menu at top of Blender window). Sooo click the “File paths” button, then look at “Scripts” text box. By default, the value there is “//” (2 slashes) which means current directory as the currently opened .blend file and this also means that any compiled .py files (ie those that carry .pyc extednsion already) AND placed in THAT directory, are accessible by “import” clause which is usually written at the beginning of scripts. The trick is that user CAN change THIS directory, ie customise it…

I use these capabilities of BLENDER to set-up a place of some modules of useful py-procedures that I created and which I want to use SOMETIMES.

So let’s consider a case you have a module called General.pyc containing some useful procs… You can access it when you need it similarly to what you need to write to access Draw module, for example… It is like this:

from Blender import *
import bpy
import math
import General

# ....................

def Recalc_coords():
    sce =
    ob =
    me = ob.getData(mesh=1)
    n = len(me.verts)
    for i in range(n):
        x = General.UsefulFunction(me.verts[i].co.x)
        y = General.UsefulFunction(me.verts[i].co.y)
        print x,y

# ....................

In the above, you import modules you need, then you call some procs from bpy module, then a function from General module… Just because you like to use it HERE!!! Therefore, for WHAT is in THAT directory, you can select whether to use or not :wink:

In the above case, THAT directory is still current directory where the .blend is… At me, the value is set to a specific directory like “C:\bla-bla-bla\My_modules” which means that the “General” module is easily accessible at any .blend file I use by means of “import” command in the .py code. It is NOT necessary THAT directory to have anything in common with your installation dir… THIS also does not brake the link to your other scripts placed in your …blender\scripts directory!!! :spin:

Shoud you need different versions of module(s) (custom files you can refer by “import” command), you may wish to set the value of the text box to be, for example, “\Modules” --> which means you NEED to have a “Modules” sub-directory of the dir where your .blend is placed… This is a nice option for developers but you need to be careful which version of files in THAT directory you are currently using :o