include the blendfile name when executing python scripts, so when using libraries you can tell where the script is stored which raises an error.
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
#include "MEM_guardedalloc.h"
|
||||
#include "BKE_text.h" /* txt_to_buf */
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_global.h" /* grr, only for G.sce */
|
||||
#include "BLI_listbase.h"
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -55,6 +56,12 @@ void bpy_import_main_set(struct Main *maggie)
|
||||
bpy_import_main= maggie;
|
||||
}
|
||||
|
||||
/* returns a dummy filename for a textblock so we can tell what file a text block comes from */
|
||||
void bpy_text_filename_get(char *fn, Text *text)
|
||||
{
|
||||
sprintf(fn, "%s/%s", text->id.lib ? text->id.lib->filename : G.sce, text->id.name+2);
|
||||
}
|
||||
|
||||
PyObject *bpy_text_import( Text *text )
|
||||
{
|
||||
char *buf = NULL;
|
||||
@@ -62,8 +69,11 @@ PyObject *bpy_text_import( Text *text )
|
||||
int len;
|
||||
|
||||
if( !text->compiled ) {
|
||||
char fn_dummy[256];
|
||||
bpy_text_filename_get(fn_dummy, text);
|
||||
|
||||
buf = txt_to_buf( text );
|
||||
text->compiled = Py_CompileString( buf, text->id.name+2, Py_file_input );
|
||||
text->compiled = Py_CompileString( buf, fn_dummy, Py_file_input );
|
||||
MEM_freeN( buf );
|
||||
|
||||
if( PyErr_Occurred( ) ) {
|
||||
|
@@ -50,6 +50,9 @@ PyObject* bpy_text_import( struct Text *text );
|
||||
PyObject* bpy_text_import_name( char *name, int *found );
|
||||
PyObject* bpy_text_reimport( PyObject *module, int *found );
|
||||
/* void bpy_text_clear_modules( int clear_all );*/ /* Clear user modules */
|
||||
|
||||
void bpy_text_filename_get(char *fn, struct Text *text);
|
||||
|
||||
extern PyMethodDef bpy_import_meth[];
|
||||
extern PyMethodDef bpy_reload_meth[];
|
||||
|
||||
|
@@ -327,16 +327,17 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
|
||||
}
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
py_dict = CreateGlobalDictionary(C, text?text->id.name+2:fn);
|
||||
|
||||
if (text) {
|
||||
char fn_dummy[FILE_MAXDIR];
|
||||
bpy_text_filename_get(fn_dummy, text);
|
||||
py_dict = CreateGlobalDictionary(C, fn_dummy);
|
||||
|
||||
if( !text->compiled ) { /* if it wasn't already compiled, do it now */
|
||||
char *buf = txt_to_buf( text );
|
||||
|
||||
text->compiled =
|
||||
Py_CompileString( buf, text->id.name+2, Py_file_input );
|
||||
Py_CompileString( buf, fn_dummy, Py_file_input );
|
||||
|
||||
MEM_freeN( buf );
|
||||
|
||||
@@ -347,7 +348,10 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
|
||||
if(text->compiled)
|
||||
py_result = PyEval_EvalCode( text->compiled, py_dict, py_dict );
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
py_dict = CreateGlobalDictionary(C, fn);
|
||||
|
||||
FILE *fp= fopen(fn, "r");
|
||||
if(fp) {
|
||||
#ifdef _WIN32
|
||||
|
Reference in New Issue
Block a user