Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillian Padovani Germano <wpgermano@gmail.com>2005-03-19 09:24:55 +0300
committerWillian Padovani Germano <wpgermano@gmail.com>2005-03-19 09:24:55 +0300
commita96ed881dc04d0a2ce6ab742f7682042e466b0a7 (patch)
treed5d787dc224d4b7c3f3e3d64a98bef0525d436e9
parentcbbe236f9237cd7a942e250493b6c7402300deb7 (diff)
BPython:
- Scripts: fixed error in "Save Current Theme" which prevented it from automatically updating script registration in menus. cosmetic changes in a couple of Campbell's sel_same.py script strings + more descriptive name for its new menu place (3d view, face mode -> select menu). small updates to help_browser.py script. The above changes are related to this: - Added new script menu entries: Render (for exporters to renderers), Themes, FaceSelect (this already at the proper place). Updated Scripts win->Scripts menu so it won't show all available entries, only the ones we mean to see there. - Updated menu registration so that scripts folders can become trees. The release/scripts/ dir should be updated soon with subdirs like converters/, modifiers/, generators/ or whatever -- better discuss first (or is it? /me afraid of long irc discussions during meetings :) ). - Modules: Blender: added 'udatadir' option to .Get() function and added var Blender.mode to tell if Blender is in bg or interactive mode. NMesh: added Campbell's nmesh.transform(matrix, recalc_normals = False) method (reworked, so my fault if it doesn't work). - Bugs fixed: #2123: http://projects.blender.org/tracker/?func=detail&atid=125&aid=2123&group_id=9 Reported by Ken Hughes (thanks!), who also found the exact problem later (it was in Text.Load, not with script links -- if only I had checked emails these days ... lost > 1 hour today to find the problem: passed filename to M_Text_Load was later being written over by a function called by add_text). Also saw that Text.Load wasn't checking existence of passed filename (duh!), now it does. #1655: http://projects.blender.org/tracker/?func=detail&atid=125&aid=1655&group_id=9 Reported by Chris Want (thanks!): command line "blender -P script" not working properly for bg mode ("blender -b blendfile -P script"). Had to make some small updates to get it working (bg mode for scripts was never explicitely handled, it worked due to collateral effects, let's say), interested readers can check the report after I update it or the API_intro.py doc file. After more testing we can make further updates. Updated many places to not call redraws if in bg mode, now it is officially available. Blender outputs its own info when rendering in bg mode, if that is considered a nuissance we'll have to add a few "if (during_script())" calls outside bpython. - Removed a few warnings here and there and also updated docs.
-rw-r--r--release/scripts/help_browser.py6
-rw-r--r--release/scripts/save_theme.py17
-rw-r--r--release/scripts/sel_same.py26
-rw-r--r--source/blender/python/BPY_extern.h4
-rw-r--r--source/blender/python/BPY_interface.c150
-rw-r--r--source/blender/python/BPY_menus.c472
-rw-r--r--source/blender/python/BPY_menus.h34
-rw-r--r--source/blender/python/SConscript2
-rw-r--r--source/blender/python/api2_2x/Blender.c221
-rw-r--r--source/blender/python/api2_2x/Ipo.c2
-rw-r--r--source/blender/python/api2_2x/NMesh.c115
-rw-r--r--source/blender/python/api2_2x/Sound.c6
-rw-r--r--source/blender/python/api2_2x/Text.c51
-rw-r--r--source/blender/python/api2_2x/Window.c48
-rw-r--r--source/blender/python/api2_2x/doc/API_intro.py85
-rw-r--r--source/blender/python/api2_2x/doc/Blender.py48
-rw-r--r--source/blender/python/api2_2x/doc/NMesh.py53
-rw-r--r--source/blender/python/api2_2x/doc/Window.py14
-rw-r--r--source/blender/python/api2_2x/gen_utils.c8
-rw-r--r--source/blender/python/api2_2x/gen_utils.h3
-rw-r--r--source/blender/python/api2_2x/sceneRender.c102
-rw-r--r--source/blender/src/drawtext.c2
-rw-r--r--source/blender/src/header_script.c9
-rw-r--r--source/blender/src/header_view3d.c19
24 files changed, 951 insertions, 546 deletions
diff --git a/release/scripts/help_browser.py b/release/scripts/help_browser.py
index 550a494c97b..bcac4b791d2 100644
--- a/release/scripts/help_browser.py
+++ b/release/scripts/help_browser.py
@@ -380,7 +380,7 @@ def parse_help_info(script):
fname = bsys.join(path, script.fname)
if not bsys.exists(fname):
- Draw.PupMenu('IO Error|Couldn\'t find script %s' % fname)
+ Draw.PupMenu('IO Error: Couldn\'t find script %s' % fname)
return None
f = file(fname, 'r')
@@ -473,7 +473,7 @@ def parse_bpymenus(lines):
i += 1
l = lines[i].strip()
- AllGroups.reverse()
+# AllGroups.reverse()
def create_group_menus():
@@ -554,7 +554,7 @@ def gui(): # drawing the screen
if SCREEN == START_SCREEN:
x = PADDING
- bw = 70
+ bw = 85
bh = 25
hincr = 50
diff --git a/release/scripts/save_theme.py b/release/scripts/save_theme.py
index 4713c63a9ff..a79de94f4ea 100644
--- a/release/scripts/save_theme.py
+++ b/release/scripts/save_theme.py
@@ -1,7 +1,7 @@
#!BPY
"""
-Name: 'Save Current Theme'
+Name: 'Save Current Theme...'
Blender: 236
Group: 'Export'
Tooltip: 'Save current theme as a bpython script'
@@ -71,14 +71,14 @@ def write_theme(filename):
# \"\"\"
# Name: '%s'
-# Blender: 234
-# Group: 'Theme'
+# Blender: 236
+# Group: 'Themes'
# Tooltip: 'Change current theme'
# \"\"\"
__%s__ = "????"
__%s__ = "1.0"
-__%s__ = [""]
+__%s__ = ["blender"]
__%s__ = \"\"\"\\
You can edit this section to write something about your script that can
be read then with the Scripts Help Browser script in Blender.
@@ -112,10 +112,9 @@ theme = Theme.New('%s')
fout.write('\nBlender.Redraw(-1)')
fout.close()
+ try:
+ Blender.UpdateMenus()
+ except:
+ Blender.Draw.PupMenu("Warning - check console!%t|Menus could not be automatically updated")
FileSelector(write_theme, "Save Current Theme", default_fname)
-
-try:
- Blender.UpdateMenus()
-except:
- Blender.Draw.PupMenu("Warning - check console!%t|Menus could not be automatically updated")
diff --git a/release/scripts/sel_same.py b/release/scripts/sel_same.py
index f37d1083c48..1ff39d38f4c 100644
--- a/release/scripts/sel_same.py
+++ b/release/scripts/sel_same.py
@@ -1,10 +1,10 @@
#!BPY
"""
-Name: 'Select Same Faces'
+Name: 'Similar to Active'
Blender: 234
-Group: 'UV'
-Tooltip: 'Select faces if attributes match the active'
+Group: 'FaceSelect'
+Tooltip: 'Select faces that match a given attribute of the active face'
"""
__author__ = "Campbell Barton"
@@ -28,7 +28,7 @@ script and choose the selection rule: by same (or similar for some itens):
- area;<br>
- proportions;<br>
- normal vector;<br>
-- co-planar.
+- coplanar.
Another menu will ask if the script should add, subtract, overwrite or
overwrite inverse of current current selection. For some choices like vcolors,
@@ -80,7 +80,7 @@ from math import sqrt
# Sanity checks #
#====================================#
def error(str):
- Draw.PupMenu('ERROR%t|'+str)
+ Draw.PupMenu('ERROR: '+str)
af = None
selection = Object.GetSelected()
if len(selection) == 0:
@@ -88,7 +88,7 @@ if len(selection) == 0:
else:
object = Object.GetSelected()[0]
if object.getType() != 'Mesh':
- error('Not a mesh')
+ error('Active object must be a mesh')
else:
mesh = object.getData()
@@ -97,7 +97,7 @@ else:
if af: af = mesh.faces[af]
if af == None:
- error('no active face')
+ error('No active face')
else: # Okay everything seems sane
@@ -105,16 +105,16 @@ else: # Okay everything seems sane
# Popup menu to select the functions #
#====================================#
method = Draw.PupMenu(\
- 'Select Same as Active%t|\
+ 'Selection Attribute%t|\
Material|\
UV Image|\
Face Mode|\
Vertex Colours|\
- UV CO-Ords|\
+ UV Coordinates|\
Area|\
- Proportions|\
- Normal|\
- Co-Planer|')
+ Edge Proportions|\
+ Normal Vector|\
+ Coplanar|')
if method != -1:
#================================================#
@@ -389,7 +389,7 @@ else: # Okay everything seems sane
if limit != None:
get_same_normal(limit)
elif method == 9: # coplaner
- limit = getLimit('coplaner limit: ')
+ limit = getLimit('coplanar limit: ')
if limit != None:
get_same_coplaner(limit)
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h
index 48c5126c22b..ab981939987 100644
--- a/source/blender/python/BPY_extern.h
+++ b/source/blender/python/BPY_extern.h
@@ -52,7 +52,7 @@ extern "C" {
int BPY_Err_getLinenumber( void );
const char *BPY_Err_getFilename( void );
/* void BPY_Err_Handle(struct Text *text); */
- int BPY_txt_do_python( struct SpaceText *st );
+ int BPY_txt_do_python_Text( struct Text *text );
int BPY_menu_do_python( short menutype, int event );
void BPY_run_python_script( char *filename );
void BPY_free_compiled_text( struct Text *text );
@@ -78,7 +78,7 @@ extern "C" {
void init_syspath( int first_time );
void syspath_append( char *dir );
- char *bpy_gethome( void );
+ char *bpy_gethome( int append_scriptsdir );
#ifdef __cplusplus
} /* extern "C" */
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c
index e1028d75475..739bc13e45d 100644
--- a/source/blender/python/BPY_interface.c
+++ b/source/blender/python/BPY_interface.c
@@ -77,6 +77,7 @@
#include "api2_2x/EXPP_interface.h"
#include "api2_2x/constant.h"
+#include "api2_2x/gen_utils.h"
#include "api2_2x/modules.h"
/* bpy_registryDict is declared in api2_2x/Registry.h and defined
@@ -356,17 +357,22 @@ const char *BPY_Err_getFilename( void )
/*****************************************************************************/
PyObject *traceback_getFilename( PyObject * tb )
{
- PyObject *v;
+ PyObject *v = NULL;
/* co_filename is in f_code, which is in tb_frame, which is in tb */
v = PyObject_GetAttrString( tb, "tb_frame" );
- Py_XDECREF( v );
- v = PyObject_GetAttrString( v, "f_code" );
- Py_XDECREF( v );
- v = PyObject_GetAttrString( v, "co_filename" );
+ if (v) {
+ Py_DECREF( v );
+ v = PyObject_GetAttrString( v, "f_code" );
+ if (v) {
+ Py_DECREF( v );
+ v = PyObject_GetAttrString( v, "co_filename" );
+ }
+ }
- return v;
+ if (v) return v;
+ else return PyString_FromString("unknown");
}
/****************************************************************************
@@ -429,11 +435,8 @@ void BPY_Err_Handle( char *script_name )
while( 1 ) {
v = PyObject_GetAttrString( tb, "tb_next" );
- if( v == Py_None
- ||
- strcmp( PyString_AsString
- ( traceback_getFilename( v ) ),
- script_name ) ) {
+ if( !v || v == Py_None ||
+ strcmp(PyString_AsString(traceback_getFilename(v)), script_name)) {
break;
}
@@ -442,12 +445,16 @@ void BPY_Err_Handle( char *script_name )
}
v = PyObject_GetAttrString( tb, "tb_lineno" );
- g_script_error.lineno = PyInt_AsLong( v );
- Py_XDECREF( v );
+ if (v) {
+ g_script_error.lineno = PyInt_AsLong(v);
+ Py_DECREF(v);
+ }
v = traceback_getFilename( tb );
- strncpy( g_script_error.filename, PyString_AsString( v ),
- FILENAME_LENGTH );
- Py_XDECREF( v );
+ if (v) {
+ strncpy( g_script_error.filename, PyString_AsString( v ),
+ FILENAME_LENGTH );
+ Py_DECREF(v);
+ }
Py_DECREF( tb );
}
@@ -543,56 +550,48 @@ int BPY_txt_do_python_Text( struct Text *text )
}
/****************************************************************************
-* Description: The original function of this name has been refactored
-* into BPY_txt_do_python_Text. That version is needed for the command
-* line support for Python. This is here to keep the interface the
-* same and reduce code changes elsewhere.
-****************************************************************************/
-int BPY_txt_do_python( struct SpaceText *st )
-{
- return BPY_txt_do_python_Text( st->text );
-}
-
-/****************************************************************************
* Description: Called from command line to run a Python script
* automatically.
****************************************************************************/
void BPY_run_python_script( char *fn )
{
Text *text = NULL;
- int is_blenText = 0;
+ int is_blender_text = 0;
- if( !BLI_exists( fn ) ) { /* if there's no such filename ... */
+ if (!BLI_exists(fn)) { /* if there's no such filename ... */
text = G.main->text.first; /* try an already existing Blender Text */
- while( text ) {
- if( !strcmp( fn, text->id.name + 2 ) )
- break;
+
+ while (text) {
+ if (!strcmp(fn, text->id.name + 2)) break;
text = text->id.next;
}
- if( !text ) {
- printf( "\nError: no such file or Blender text -- %s.\n", fn );
+ if (text == NULL) {
+ printf("\nError: no such file or Blender text -- %s.\n", fn);
return;
- } else
- is_blenText = 1; /* fn is already a Blender Text */
+ }
+ else is_blender_text = 1; /* fn is already a Blender Text */
}
- if( !is_blenText )
- text = add_text( fn );
- if( text == NULL ) {
- printf( "Error in BPY_run_python_script: couldn't create Blender text " "from %s\n", fn );
- // Chris: On Windows if I continue I just get a segmentation
- // violation. To get a baseline file I exit here.
- exit( 2 );
+ else {
+ text = add_text(fn);
+
+ if (text == NULL) {
+ printf("\nError in BPY_run_python_script:\n"
+ "couldn't create Blender text from %s\n", fn);
+ /* Chris: On Windows if I continue I just get a segmentation
+ * violation. To get a baseline file I exit here. */
+ exit(2);
+ /* return; */
+ }
}
- if( BPY_txt_do_python_Text( text ) != 1 ) {
- printf( "\nError executing Python script from command-line:\n"
- "%s (at line %d).\n", fn, BPY_Err_getLinenumber( ) );
+ if (BPY_txt_do_python_Text(text) != 1) {
+ printf("\nError executing Python script from command-line:\n"
+ "%s (at line %d).\n", fn, BPY_Err_getLinenumber());
}
- if( !is_blenText )
- free_libblock( &G.main->text, text );
+ if (!is_blender_text) free_libblock(&G.main->text, text);
}
/****************************************************************************
@@ -611,7 +610,6 @@ int BPY_menu_do_python( short menutype, int event )
FILE *fp = NULL;
char *buffer, *s;
char filestr[FILE_MAXDIR + FILE_MAXFILE];
- char dirname[FILE_MAXDIR];
char scriptname[21];
Script *script = NULL;
int len;
@@ -654,13 +652,9 @@ int BPY_menu_do_python( short menutype, int event )
}
if( pym->dir ) /* script is in U.pythondir */
- BLI_make_file_string( "/", filestr, U.pythondir,
- pym->filename );
- else { /* script is in ~/.blender/scripts/ */
- BLI_make_file_string( "/", dirname, bpy_gethome( ),
- "scripts" );
- BLI_make_file_string( "/", filestr, dirname, pym->filename );
- }
+ BLI_make_file_string( "/", filestr, U.pythondir, pym->filename );
+ else /* script is in ~/.blender/scripts/ */
+ BLI_make_file_string( "/", filestr, bpy_gethome(1), pym->filename );
fp = fopen( filestr, "rb" );
if( !fp ) {
@@ -692,9 +686,10 @@ int BPY_menu_do_python( short menutype, int event )
* each group will be put to code this properly) */
switch ( menutype ) {
- case PYMENU_IMPORT: /* first 3 were handled in header_info.c */
+ case PYMENU_IMPORT: /* first 4 were handled in header_info.c */
case PYMENU_EXPORT:
case PYMENU_HELP:
+ case PYMENU_RENDER:
case PYMENU_WIZARDS:
break;
@@ -1033,8 +1028,7 @@ void BPY_do_pyscript( ID * id, short event )
disable_where_scriptlink( during_slink );
/* set globals in Blender module to identify scriptlink */
- Py_INCREF( Py_True );
- PyDict_SetItemString( g_blenderdict, "bylink", Py_True );
+ PyDict_SetItemString( g_blenderdict, "bylink", EXPP_incr_ret_True() );
PyDict_SetItemString( g_blenderdict, "link",
ID_asPyObject( id ) );
PyDict_SetItemString( g_blenderdict, "event",
@@ -1074,8 +1068,7 @@ void BPY_do_pyscript( ID * id, short event )
/* cleanup bylink flag and clear link so PyObject
* can be released
*/
- Py_INCREF( Py_False );
- PyDict_SetItemString( g_blenderdict, "bylink", Py_False );
+ PyDict_SetItemString( g_blenderdict, "bylink", EXPP_incr_ret_False() );
Py_INCREF( Py_None );
PyDict_SetItemString( g_blenderdict, "link", Py_None );
PyDict_SetItemString( g_blenderdict, "event",
@@ -1358,17 +1351,25 @@ void init_ourImport( void )
/* this makes sure BLI_gethome() returns a path with '.blender' appended
* Besides, this function now either returns userhome/.blender (if it exists)
- * or blenderInstallDir/.blender/ otherwise
+ * or blenderInstallDir/.blender/ otherwise.
+ * If append_scriptsdir is non NULL, "scripts/" is appended to the dir, to
+ * get the path to the scripts folder.
+ * Finally, if searched dir doesn't exist, NULL is returned.
*/
-char *bpy_gethome( )
+char *bpy_gethome(int append_scriptsdir)
{
static char homedir[FILE_MAXDIR];
+ static char scriptsdir[FILE_MAXDIR];
char bprogdir[FILE_MAXDIR];
char *s;
int i;
- if( homedir[0] != '\0' )
- return homedir; /* no need to search twice */
+ if (append_scriptsdir) {
+ if (scriptsdir[0] != '\0')
+ return scriptsdir;
+ }
+ else if (homedir[0] != '\0')
+ return homedir;
s = BLI_gethome( );
@@ -1378,8 +1379,13 @@ char *bpy_gethome( )
BLI_make_file_string( "/", homedir, s, ".blender/" );
/* if userhome/.blender/ exists, return it */
- if( BLI_exists( homedir ) )
- return homedir;
+ if( BLI_exists( homedir ) ) {
+ if (append_scriptsdir) {
+ BLI_make_file_string("/", scriptsdir, homedir, "scripts/");
+ if (BLI_exists (scriptsdir)) return scriptsdir;
+ }
+ else return homedir;
+ }
/* otherwise, use argv[0] (bprogname) to get .blender/ in
* Blender's installation dir */
@@ -1390,5 +1396,13 @@ char *bpy_gethome( )
PyOS_snprintf( bprogdir, i, bprogname );
BLI_make_file_string( "/", homedir, bprogdir, ".blender/" );
- return homedir;
+ if (BLI_exists(homedir)) {
+ if (append_scriptsdir) {
+ BLI_make_file_string("/", scriptsdir, homedir, "scripts/");
+ if (BLI_exists(scriptsdir)) return scriptsdir;
+ }
+ else return homedir;
+ }
+
+ return NULL;
}
diff --git a/source/blender/python/BPY_menus.c b/source/blender/python/BPY_menus.c
index a67ada0cfee..89134541e03 100644
--- a/source/blender/python/BPY_menus.c
+++ b/source/blender/python/BPY_menus.c
@@ -77,20 +77,26 @@ BPyMenu *BPyMenuTable[PYMENU_TOTAL];
static int bpymenu_group_atoi( char *str )
{
- if( !strcmp( str, "Import" ) )
- return PYMENU_IMPORT;
- else if( !strcmp( str, "Export" ) )
+ if( !strcmp( str, "Export" ) )
return PYMENU_EXPORT;
+ else if( !strcmp( str, "Import" ) )
+ return PYMENU_IMPORT;
else if( !strcmp( str, "Help" ) )
return PYMENU_HELP;
- else if( !strcmp( str, "Websites" ) || !strcmp( str, "HelpWebsites" ) )
+ else if( !strcmp( str, "HelpWebsites" ) )
return PYMENU_HELPWEBSITES;
- else if( !strcmp( str, "System" ) || !strcmp( str, "HelpSystem" ) )
+ else if( !strcmp( str, "HelpSystem" ) )
return PYMENU_HELPSYSTEM;
- else if( !strcmp( str, "Add" ) )
- return PYMENU_ADD;
+ else if( !strcmp( str, "Render" ) )
+ return PYMENU_RENDER;
+ else if( !strcmp( str, "Object" ) )
+ return PYMENU_OBJECT;
else if( !strcmp( str, "Mesh" ) )
return PYMENU_MESH;
+ else if( !strncmp( str, "Theme", 5 ) )
+ return PYMENU_THEMES;
+ else if( !strcmp( str, "Add" ) )
+ return PYMENU_ADD;
else if( !strcmp( str, "Wizards" ) )
return PYMENU_WIZARDS;
else if( !strcmp( str, "Animation" ) )
@@ -99,8 +105,8 @@ static int bpymenu_group_atoi( char *str )
return PYMENU_MATERIALS;
else if( !strcmp( str, "UV" ) )
return PYMENU_UV;
- else if( !strcmp( str, "Object" ) )
- return PYMENU_OBJECT;
+ else if( !strcmp( str, "FaceSelect" ) )
+ return PYMENU_FACESELECT;
/* "Misc" or an inexistent group name: use misc */
else
return PYMENU_MISC;
@@ -109,12 +115,12 @@ static int bpymenu_group_atoi( char *str )
char *BPyMenu_group_itoa( short menugroup )
{
switch ( menugroup ) {
- case PYMENU_IMPORT:
- return "Import";
- break;
case PYMENU_EXPORT:
return "Export";
break;
+ case PYMENU_IMPORT:
+ return "Import";
+ break;
case PYMENU_ADD:
return "Add";
break;
@@ -122,14 +128,23 @@ char *BPyMenu_group_itoa( short menugroup )
return "Help";
break;
case PYMENU_HELPWEBSITES:
- return "Websites";
+ return "HelpWebsites";
break;
case PYMENU_HELPSYSTEM:
- return "System";
+ return "HelpSystem";
+ break;
+ case PYMENU_RENDER:
+ return "Render";
+ break;
+ case PYMENU_OBJECT:
+ return "Object";
break;
case PYMENU_MESH:
return "Mesh";
break;
+ case PYMENU_THEMES:
+ return "Themes";
+ break;
case PYMENU_WIZARDS:
return "Wizards";
break;
@@ -142,8 +157,8 @@ char *BPyMenu_group_itoa( short menugroup )
case PYMENU_UV:
return "UV";
break;
- case PYMENU_OBJECT:
- return "Object";
+ case PYMENU_FACESELECT:
+ return "FaceSelect";
break;
case PYMENU_MISC:
return "Misc";
@@ -284,7 +299,7 @@ static void bpymenu_set_tooltip( BPyMenu * pymenu, char *tip )
* if found, update it with new info, otherwise create a new one and fill it.
*/
static BPyMenu *bpymenu_AddEntry( short group, short version, char *name,
- char *fname, int whichdir, char *tooltip )
+ char *fname, int is_userdir, char *tooltip )
{
BPyMenu *menu, *next = NULL, **iter;
int nameclash = 0;
@@ -301,7 +316,7 @@ static BPyMenu *bpymenu_AddEntry( short group, short version, char *name,
* accept and let the new one override the other.
* - otherwise, report the error and return NULL. */
if( menu ) {
- if( menu->dir < whichdir ) { /* new one is in U.pythondir */
+ if( menu->dir < is_userdir ) { /* new one is in U.pythondir */
nameclash = 1;
if( menu->name )
MEM_freeN( menu->name );
@@ -313,9 +328,9 @@ static BPyMenu *bpymenu_AddEntry( short group, short version, char *name,
bpymenu_RemoveAllSubEntries( menu->submenus );
next = menu->next;
} else { /* they are in the same dir */
- if( DEBUG ) {
- printf( "\nWarning: script %s's menu name is already in use.\n", fname );
- printf( "Edit the script and change its Name: '%s' field, please.\n" "Note: if you really want two scripts in the same menu with\n" "the same name, keep one in the default dir and the other in\n" "the user defined dir, where it will take precedence.\n", name );
+ if (DEBUG) {
+ printf("\nWarning: script %s's menu name is already in use.\n", fname );
+ printf("Edit the script and change its Name: '%s' field, please.\n" "Note: if you really want two scripts in the same menu with\n" "the same name, keep one in the default dir and the other in\n" "the user defined dir, where it will take precedence.\n", name);
}
return NULL;
}
@@ -331,7 +346,7 @@ static BPyMenu *bpymenu_AddEntry( short group, short version, char *name,
menu->tooltip = NULL;
if( tooltip )
menu->tooltip = BLI_strdup( tooltip );
- menu->dir = whichdir;
+ menu->dir = is_userdir;
menu->submenus = NULL;
menu->next = next; /* non-NULL if menu already existed */
@@ -399,7 +414,7 @@ static int bpymenu_CreateFromFile( void )
{
FILE *fp;
char line[255], w1[255], w2[255], tooltip[255], *tip;
- int parsing, version, whichdir;
+ int parsing, version, is_userdir;
short group;
BPyMenu *pymenu = NULL;
@@ -409,7 +424,7 @@ static int bpymenu_CreateFromFile( void )
BPyMenuTable[group] = NULL;
/* let's try to open the file with bpymenu data */
- BLI_make_file_string( "/", line, bpy_gethome( ), BPYMENU_DATAFILE );
+ BLI_make_file_string( "/", line, bpy_gethome(0), BPYMENU_DATAFILE );
fp = fopen( line, "rb" );
@@ -464,7 +479,7 @@ static int bpymenu_CreateFromFile( void )
parsing =
sscanf( line,
"'%[^']' %d %s %d '%[^']'\n",
- w1, &version, w2, &whichdir,
+ w1, &version, w2, &is_userdir,
tooltip );
if( parsing <= 0 ) { /* invalid line, get rid of it */
@@ -474,7 +489,7 @@ static int bpymenu_CreateFromFile( void )
pymenu = bpymenu_AddEntry( group,
( short ) version,
- w1, w2, whichdir,
+ w1, w2, is_userdir,
tip );
if( !pymenu ) {
puts( "BPyMenus error: couldn't create bpymenu entry.\n" );
@@ -506,7 +521,7 @@ static void bpymenu_WriteDataFile( void )
char fname[FILE_MAXDIR + FILE_MAXFILE];
int i;
- BLI_make_file_string( "/", fname, bpy_gethome( ), BPYMENU_DATAFILE );
+ BLI_make_file_string( "/", fname, bpy_gethome(0), BPYMENU_DATAFILE );
fp = fopen( fname, "w" );
if( !fp ) {
@@ -583,194 +598,242 @@ void BPyMenu_PrintAllEntries( void )
}
}
-/** Creates BPyMenu entries for scripts from directory.
+/* bpymenu_ParseFile:
+ * recursively scans folders looking for scripts to register.
*
* This function scans the scripts directory looking for .py files with the
* right header and menu info, using that to fill the bpymenu structs.
- * whichdir defines if the script is in the default scripts dir or the
- * user defined one (U.pythondir: whichdir == 1).
+ * is_userdir defines if the script is in the default scripts dir or the
+ * user defined one (U.pythondir: is_userdir == 1).
* Speed is important.
- * <code>whichdir</code> defines if the script is in the default scripts dir
- * or the user defined one (U.pythondir: <code>whichdir == 1</code>).
- * <p>
- * The first line of the script must be '<code>#!BPY</code>'.
+ *
+ * The first line of the script must be '#!BPY'.
* The header registration lines must appear between the first pair of
- * '<code># \"\"\"</code>' and follow this order (the single-quotes are part of
+ * '\"\"\"' and follow this order (the single-quotes are part of
* the format):
- * <p>
- * <code>
- * # \"\"\"<br>
- * # Name: 'script name for the menu'<br>
- * # Blender: <code>short int</code> (minimal Blender version)<br>
- * # Group: 'group name' (defines menu)<br>
- * # Submenu: 'submenu name' related_1word_arg<br>
- * # Tooltip: 'tooltip for the menu'<br>
+ *
* # \"\"\"<br>
- * </code>
- * <p>
+ * # Name: 'script name for the menu'
+ * # Blender: <code>short int</code> (minimal Blender version)
+ * # Group: 'group name' (defines menu)
+ * # Submenu: 'submenu name' related_1word_arg
+ * # Tooltip: 'tooltip for the menu'
+ * # \"\"\"
+ *
* Notes:
- * <ul>
- * <li> There may be more than one submenu line, or none:
- * Submenus and the tooltip are optional;
- * <li> The Blender version is the same number reported by
- * <code>Blender.Get('version')</code> in BPython or <code>G.version</code>
- * in C;
- * <li> Line length must be less than 99.
- * <li> Script headers as python documentation strings without the leading
- * hash character (#) should no longer be used.
- * </ul>
- *
- * @param dirname Directory name to scan.
- * @param whichdir Specifies the directory. 1 if user defined script directory,
- * else default script directory.
- * @return 0 on success.
+ *
+ * - Commenting out header lines with "#" is optional, but recommended.
+ * - There may be more than one submenu line, or none:
+ * submenus and the tooltip are optional;
+ * - The Blender version is the same number reported by
+ * Blender.Get('version') in BPython or G.version in C;
+ * - Line length must be less than 99.
*/
-
-static int bpymenu_CreateFromDir( char *dirname, int whichdir )
+static int bpymenu_ParseFile(FILE *file, char *fname, int is_userdir)
{
- DIR *dir; /* directory stream object */
- FILE *currentFile; /* file stream object */
- struct dirent *dirEntry; /* directory entry */
- struct stat fileStatus;
- char *fileExtension;
- char fileName[FILE_MAXFILE + FILE_MAXDIR]; /* filename including path */
- /* parser variables */
char line[100];
char head[100];
char middle[100];
char tail[100];
- int nMatches;
- int parserState;
- /* script header variables */
- char scriptName[100];
- int scriptBlender;
- int scriptGroup;
+ int matches;
+ int parser_state;
+
+ char script_name[100];
+ int script_version;
+ int script_group;
+
BPyMenu *scriptMenu = NULL;
- /* other */
- int returnValue = 0;
-
- /* open directory stream */
+
+ if (file != NULL) {
+ parser_state = 1; /* state of parser, 0 to terminate */
+
+ while ((parser_state != 0) && (fgets(line, 100, file) != NULL)) {
+
+ switch (parser_state) {
+
+ case 1: /* !BPY */
+ if (strncmp(line, "#!BPY", 5) == 0) {
+ parser_state++;
+ } else {
+ parser_state = 0;
+ }
+ break;
+
+ case 2: /* \"\"\" */
+ if ((strstr(line, "\"\"\""))) {
+ parser_state++;
+ }
+ break;
+
+ case 3: /* Name: 'script name for the menu' */
+ matches = sscanf(line, "%[^']'%[^']'%c", head, script_name, tail);
+ if ((matches == 3) && (strstr(head, "Name:") != NULL)) {
+ parser_state++;
+ } else {
+ if (DEBUG)
+ fprintf(stderr, "BPyMenus error: Wrong 'Name' line: %s\n", fname);
+ parser_state = 0;
+ }
+ break;
+
+ case 4: /* Blender: <short int> */
+ matches = sscanf(line, "%[^1234567890]%i%c", head, &script_version,
+ tail);
+ if (matches == 3) {
+ parser_state++;
+ } else {
+ if (DEBUG)
+ fprintf(stderr,"BPyMenus error: Wrong 'Blender' line: %s\n",fname);
+ parser_state = 0;
+ }
+ break;
+
+ case 5: /* Group: 'group name' */
+ matches = sscanf(line, "%[^']'%[^']'%c", head, middle, tail);
+ if ((matches == 3) && (strstr(head, "Group:") != NULL)) {
+ script_group = bpymenu_group_atoi(middle);
+ if (script_group < 0) {
+ if (DEBUG)
+ fprintf(stderr, "BPyMenus error: Unknown group \"%s\": %s\n",
+ middle, fname);
+ parser_state = 0;
+ }
+
+ else { /* register script */
+ scriptMenu = bpymenu_AddEntry(script_group,
+ (short int)script_version, script_name, fname, is_userdir,NULL);
+ if (scriptMenu == NULL) {
+ if (DEBUG)
+ fprintf(stderr,
+ "BPyMenus error: Couldn't create entry for: %s\n", fname);
+ parser_state = 0;
+ } else {
+ parser_state++;
+ }
+ }
+
+ } else {
+ if (DEBUG)
+ fprintf(stderr, "BPyMenus error: Wrong 'Group' line: %s\n",fname);
+ parser_state = 0;
+ }
+ break;
+
+ case 6: /* optional elements */
+ /* Submenu: 'submenu name' related_1word_arg */
+ matches = sscanf(line, "%[^']'%[^']'%s\n", head, middle, tail);
+ if ((matches == 3) && (strstr(head, "Submenu:") != NULL)) {
+ bpymenu_AddSubEntry(scriptMenu, middle, tail);
+ } else {
+ /* Tooltip: 'tooltip for the menu */
+ matches = sscanf(line, "%[^']'%[^']'%c", head, middle, tail);
+ if ((matches == 3) && ((strstr(head, "Tooltip:") != NULL) ||
+ (strstr(head, "Tip:") != NULL))) {
+ bpymenu_set_tooltip(scriptMenu, middle);
+ }
+ parser_state = 0;
+ }
+ break;
+
+ default:
+ parser_state = 0;
+ break;
+ }
+ }
+ }
+
+ else { /* shouldn't happen, it's checked in bpymenus_ParseDir */
+ if (DEBUG)
+ fprintf(stderr, "BPyMenus error: Couldn't open %s.\n", fname);
+ return -1;
+ }
+
+ return 0;
+}
+
+/* bpymenu_ParseDir:
+ * recursively scans folders looking for scripts to register.
+ *
+ * This function scans the scripts directory looking for .py files with the
+ * right header and menu info.
+ * - is_userdir defines if the script is in the default scripts dir or the
+ * user defined one (U.pythondir: is_userdir == 1);
+ * - parentdir is the parent dir name to store as part of the script filename,
+ * if we're down a subdir.
+ * Speed is important.
+ */
+static int bpymenu_ParseDir(char *dirname, char *parentdir, int is_userdir )
+{
+ DIR *dir;
+ FILE *file = NULL;
+ struct dirent *de;
+ struct stat status;
+ char *file_extension;
+ char path[FILE_MAXFILE + FILE_MAXDIR];
+ char subdir[FILE_MAXDIR];
+ char *s = NULL;
+
dir = opendir(dirname);
+
if (dir != NULL) {
- /* directory stream opened */
- while ((dirEntry = readdir(dir)) != NULL) {
- /* Check if filename does not start with a dot,
- * ends with '.py' and is a regular file. */
- BLI_make_file_string("/", fileName, dirname, dirEntry->d_name);
- fileExtension = strstr(dirEntry->d_name, ".py");
-
- if ((strncmp(dirEntry->d_name, ".", 1) != 0)
- && (fileExtension != NULL)
- && (*(fileExtension + 3) == '\0')
- && (stat(fileName, &fileStatus) == 0)
- && (S_ISREG(fileStatus.st_mode))) {
- /* check file header */
- currentFile = fopen(fileName, "rb");
- if (currentFile != NULL) {
- parserState = 1; /* state of parser, 0 to terminate */
- while ((parserState != 0) && (fgets(line, 100, currentFile) != NULL)) {
- switch (parserState) {
- case 1: /* #!BPY */
- if (strncmp(line, "#!BPY", 5) == 0) {
- parserState++;
- } else {
- parserState = 0;
- }
- break;
- case 2: /* # \"\"\" */
- if ((strstr(line, "\"\"\""))) {
- parserState++;
- }
- break;
- case 3: /* # Name: 'script name for the menu' */
- nMatches = sscanf(line, "%[^']'%[^']'%c", head, scriptName, tail);
- if ((nMatches == 3) && (strstr(head, "Name:") != NULL)) {
- parserState++;
- } else {
- if (DEBUG) {
- fprintf(stderr, "BPyMenus error: Wrong 'Name' line: %s\n", fileName);
- }
- parserState = 0;
- }
- break;
- case 4: /* # Blender: <short int> */
- nMatches = sscanf(line, "%[^1234567890]%i%c", head, &scriptBlender, tail);
- if (nMatches == 3) {
- parserState++;
- } else {
- if (DEBUG) {
- fprintf(stderr, "BPyMenus error: Wrong 'Blender' line: %s\n", fileName);
- }
- parserState = 0;
- }
- break;
- case 5: /* # Group: 'group name' */
- nMatches = sscanf(line, "%[^']'%[^']'%c", head, middle, tail);
- if ((nMatches == 3) && (strstr(head, "Group:") != NULL)) {
- scriptGroup = bpymenu_group_atoi(middle);
- if (scriptGroup < 0) {
- if (DEBUG) {
- fprintf(stderr, "BPyMenus error: Unknown group \"%s\": %s\n", middle, fileName);
- }
- parserState = 0;
- } else {
- /* register script */
- scriptMenu = bpymenu_AddEntry(scriptGroup, (short int) scriptBlender, scriptName,
- dirEntry->d_name, whichdir, NULL);
- if (scriptMenu == NULL) {
- if (DEBUG) {
- fprintf(stderr, "BPyMenus error: Couldn't create entry for: %s\n", fileName);
- }
- parserState = 0;
- } else {
- parserState++;
- }
- }
- } else {
- if (DEBUG) {
- fprintf(stderr, "BPyMenus error: Wrong 'Group' line: %s\n", fileName);
- }
- parserState = 0;
- }
- break;
- case 6: /* optional elements */
- /* # Submenu: 'submenu name' related_1word_arg */
- nMatches = sscanf(line, "%[^']'%[^']'%s\n", head, middle, tail);
- if ((nMatches == 3) && (strstr(head, "Submenu:") != NULL)) {
- bpymenu_AddSubEntry(scriptMenu, middle, tail);
- } else {
- /* # Tooltip: 'tooltip for the menu */
- nMatches = sscanf(line, "%[^']'%[^']'%c", head, middle, tail);
- if ((nMatches == 3)
- && ((strstr(head, "Tooltip:") != NULL) || (strstr(head, "Tip:") != NULL))) {
- bpymenu_set_tooltip(scriptMenu, middle);
- }
- parserState = 0;
- }
- break;
- default:
- parserState = 0;
- break;
+ while ((de = readdir(dir)) != NULL) {
+
+ /* skip files and dirs starting with '.' or 'bpy' */
+ if ((de->d_name[0] == '.') || !strncmp(de->d_name, "bpy", 3)) {
+ continue;
+ }
+
+ BLI_make_file_string("/", path, dirname, de->d_name);
+
+ if (stat(path, &status) != 0) {
+ if (DEBUG)
+ fprintf(stderr, "stat %s failed: %s\n", path, strerror(errno));
+ }
+
+ if (S_ISREG(status.st_mode)) { /* is file */
+
+ file_extension = strstr(de->d_name, ".py");
+
+ if (file_extension && *(file_extension + 3) == '\0') {
+ file = fopen(path, "rb");
+
+ if (file) {
+ s = de->d_name;
+ if (parentdir) {
+ BLI_make_file_string(NULL, subdir, parentdir, de->d_name);
+ s = subdir;
}
+ bpymenu_ParseFile(file, s, is_userdir);
+ fclose(file);
}
- /* close file stream */
- fclose(currentFile);
- } else {
- /* open file failed */
- if(DEBUG) {
- fprintf(stderr, "BPyMenus error: Couldn't open %s.\n", dirEntry->d_name);
+
+ else {
+ if (DEBUG)
+ fprintf(stderr, "BPyMenus error: Couldn't open %s.\n", path);
}
}
}
+
+ else if (S_ISDIR(status.st_mode)) { /* is subdir */
+ s = de->d_name;
+ if (parentdir) {
+ BLI_make_file_string(NULL, subdir, parentdir, de->d_name);
+ s = subdir;
+ }
+ bpymenu_ParseDir(path, s, is_userdir);
+ }
+
}
- /* close directory stream */
closedir(dir);
- } else {
- /* open directory stream failed */
- fprintf(stderr, "opendir %s failed: %s\n", dirname, strerror(errno));
- returnValue = -1;
}
- return returnValue;
+
+ else { /* open directory stream failed */
+ if (DEBUG)
+ fprintf(stderr, "opendir %s failed: %s\n", dirname, strerror(errno));
+ return -1;
+ }
+
+ return 0;
}
static int bpymenu_GetStatMTime( char *name, int is_file, time_t * mtime )
@@ -819,7 +882,7 @@ int BPyMenu_Init( int usedir )
if( U.pythondir[0] == '\0' )
upydir = NULL;
- BLI_make_file_string( "/", dirname, bpy_gethome( ), "scripts" );
+ BLI_strncpy(dirname, bpy_gethome(1), FILE_MAXDIR);
res1 = bpymenu_GetStatMTime( dirname, 0, &tdir1 );
@@ -861,33 +924,34 @@ int BPyMenu_Init( int usedir )
if( DEBUG )
printf( "\nRegistering scripts in Blender menus ...\n\n" );
- if( !usedir ) { /* if we're not forced to use the dir */
- BLI_make_file_string( "/", fname, bpy_gethome( ),
+ if (usedir) resf = -1;
+ else { /* if we're not forced to use the dir */
+ BLI_make_file_string( "/", fname, bpy_gethome(0),
BPYMENU_DATAFILE );
resf = bpymenu_GetStatMTime( fname, 1, &tfile );
if( resf < 0 )
tfile = 0;
- }
- /* comparing dates */
+ /* comparing dates */
- if( ( tfile > tdir1 ) && ( tfile > tdir2 ) && !resf ) { /* file is newer */
- resf = bpymenu_CreateFromFile( ); /* -1 if an error occurred */
- if( !resf && DEBUG )
- printf( "Getting menu data for scripts from file: %s\n\n", fname );
- } else
- resf = -1; /* -1 to use dirs: didn't use file or it was corrupted */
+ if( ( tfile > tdir1 ) && ( tfile > tdir2 ) && !resf ) { /* file is newer */
+ resf = bpymenu_CreateFromFile( ); /* -1 if an error occurred */
+ if( !resf && DEBUG )
+ printf( "Getting menu data for scripts from file: %s\n\n", fname );
+ }
+ else resf = -1; /* -1 to use dirs: didn't use file or it was corrupted */
+ }
if( resf == -1 ) { /* use dirs */
if( DEBUG ) {
- printf( "Getting menu data for scripts from dir(s):\n%s\n", dirname );
+ printf( "Getting menu data for scripts from dir(s):\n%s\n\n", dirname );
if( upydir )
printf( "%s\n", upydir );
}
if( res1 == 0 )
- bpymenu_CreateFromDir( dirname, 0 );
+ bpymenu_ParseDir( dirname, NULL, 0 );
if( res2 == 0 )
- bpymenu_CreateFromDir( U.pythondir, 1 );
+ bpymenu_ParseDir( U.pythondir, NULL, 1 );
/* check if we got any data */
for( res1 = 0; res1 < PYMENU_TOTAL; res1++ )
diff --git a/source/blender/python/BPY_menus.h b/source/blender/python/BPY_menus.h
index 08fbfcf7d16..8848ba75a45 100644
--- a/source/blender/python/BPY_menus.h
+++ b/source/blender/python/BPY_menus.h
@@ -78,22 +78,32 @@ typedef struct BPyMenu {
* source/blender/src/, like done in header_info.c for import/export;
*/
typedef enum {
- PYMENU_WIZARDS, /* complex 'app' scripts */
- PYMENU_UV, /* UV editing tools, to go in UV/Image editor space, 'UV' menu */
- PYMENU_OBJECT,
- PYMENU_MISC,
- PYMENU_MESH,
- PYMENU_MATERIALS,
- PYMENU_HELP, /* Main Help menu items - prob best to leave for 'official' ones */
- PYMENU_HELPSYSTEM, /* Resources, troubleshooting, system tools */
- PYMENU_HELPWEBSITES, /* Help -> Websites submenu */
- PYMENU_IMPORT,
- PYMENU_EXPORT,
+ PYMENU_ADD,/* creates new objects */
PYMENU_ANIMATION,
- PYMENU_ADD, /* creates new objects */
+ PYMENU_EXPORT,
+ PYMENU_IMPORT,
+ PYMENU_MATERIALS,
+ PYMENU_MESH,
+ PYMENU_MISC,
+ PYMENU_OBJECT,
+ PYMENU_RENDER,/* exporters to external renderers */
+ PYMENU_THEMES,
+ PYMENU_UV,/* UV editing tools, to go in UV/Image editor space, 'UV' menu */
+ PYMENU_WIZARDS,/* complex 'app' scripts */
+
+ /* entries put below don't appear at the Scripts win->Scripts menu;
+ * see define right below */
+
+ PYMENU_FACESELECT,
+ PYMENU_HELP,/*Main Help menu items - prob best to leave for 'official' ones*/
+ PYMENU_HELPSYSTEM,/* Resources, troubleshooting, system tools */
+ PYMENU_HELPWEBSITES,/* Help -> Websites submenu */
+
PYMENU_TOTAL
} PYMENUHOOKS;
+#define PYMENU_SCRIPTS_MENU_TOTAL PYMENU_FACESELECT
+
/* BPyMenuTable holds all registered pymenus, as linked lists for each menu
* where they can appear (see PYMENUHOOKS enum above).
*/
diff --git a/source/blender/python/SConscript b/source/blender/python/SConscript
index 656df1354d7..1a244cec68b 100644
--- a/source/blender/python/SConscript
+++ b/source/blender/python/SConscript
@@ -43,7 +43,7 @@ source_files = ['BPY_interface.c',
'api2_2x/World.c',
'api2_2x/Image.c',
'api2_2x/Text.c',
- 'api2_2x/Text3d.c',
+ 'api2_2x/Text3d.c',
'api2_2x/Texture.c',
'api2_2x/Noise.c',
'api2_2x/charRGBA.c',
diff --git a/source/blender/python/api2_2x/Blender.c b/source/blender/python/api2_2x/Blender.c
index 7c93d540ceb..c1ecbdf7ebb 100644
--- a/source/blender/python/api2_2x/Blender.c
+++ b/source/blender/python/api2_2x/Blender.c
@@ -49,6 +49,7 @@
#include <BKE_global.h>
#include <BKE_packedFile.h>
#include <BKE_object.h>
+#include <BKE_text.h>
#include <BPI_script.h>
#include <BSE_headerbuttons.h>
#include <DNA_ID.h>
@@ -60,14 +61,11 @@
#include <BKE_ipo.h>
#include <blendef.h>
-
-
#include "gen_utils.h"
#include "modules.h"
#include "../BPY_extern.h" /* for bpy_gethome() */
#include "../BPY_menus.h" /* to update menus */
-
/**********************************************************/
/* Python API function prototypes for the Blender module. */
/**********************************************************/
@@ -77,11 +75,11 @@ static PyObject *Blender_Redraw( PyObject * self, PyObject * args );
static PyObject *Blender_Quit( PyObject * self );
static PyObject *Blender_Load( PyObject * self, PyObject * args );
static PyObject *Blender_Save( PyObject * self, PyObject * args );
+static PyObject *Blender_Run( PyObject * self, PyObject * args );
static PyObject *Blender_UpdateMenus( PyObject * self);
extern PyObject *Text3d_Init( void ); /* missing in some include */
-
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
@@ -135,6 +133,10 @@ Note 2: only .blend raises an error if file wasn't saved.\n\
\tYou can use Blender.sys.exists(filename) to make sure the file was saved\n\
\twhen writing to one of the other formats.";
+static char Blender_Run_doc[] =
+ "(script) - Run the given Python script.\n\
+(script) - the path to a file or the name of an available Blender Text.";
+
static char Blender_UpdateMenus_doc[] =
"() - Update the menus where scripts are registered. Only needed for\n\
scripts that save other new scripts in the default or user defined folders.";
@@ -149,6 +151,7 @@ static struct PyMethodDef Blender_methods[] = {
{"Quit", ( PyCFunction ) Blender_Quit, METH_NOARGS, Blender_Quit_doc},
{"Load", Blender_Load, METH_VARARGS, Blender_Load_doc},
{"Save", Blender_Save, METH_VARARGS, Blender_Save_doc},
+ {"Run", Blender_Run, METH_VARARGS, Blender_Run_doc},
{"UpdateMenus", ( PyCFunction ) Blender_UpdateMenus, METH_NOARGS,
Blender_UpdateMenus_doc},
{NULL, NULL, 0, NULL}
@@ -196,104 +199,87 @@ static PyObject *Blender_Set( PyObject * self, PyObject * args )
/*****************************************************************************/
static PyObject *Blender_Get( PyObject * self, PyObject * args )
{
- PyObject *object;
- PyObject *dict;
- char *str;
-
- if( !PyArg_ParseTuple( args, "O", &object ) ) {
- /* TODO: Do we need to generate a nice error message here? */
- return ( NULL );
+ PyObject *ret = NULL, *dict = NULL;
+ char *str = NULL;
+
+ if( !PyArg_ParseTuple( args, "s", &str ) )
+ return EXPP_ReturnPyObjError (PyExc_TypeError,
+ "expected string argument");
+
+ if( StringEqual( str, "curframe" ) )
+ ret = PyInt_FromLong( G.scene->r.cfra );
+ else if( StringEqual( str, "curtime" ) )
+ ret = PyFloat_FromDouble( frame_to_float( G.scene->r.cfra ) );
+ else if( StringEqual( str, "staframe" ) )
+ ret = PyInt_FromLong( G.scene->r.sfra );
+ else if( StringEqual( str, "endframe" ) )
+ ret = PyInt_FromLong( G.scene->r.efra );
+ else if( StringEqual( str, "filename" ) )
+ ret = PyString_FromString( G.sce );
+ else if( StringEqual( str, "homedir" ) ) {
+ char *hdir = bpy_gethome(0);
+ if( BLI_exists( hdir ))
+ ret = PyString_FromString( hdir );
+ else
+ ret = EXPP_incr_ret( Py_None );
}
+ else if( StringEqual( str, "datadir" ) ) {
+ char datadir[FILE_MAXDIR];
+
+ BLI_make_file_string( "/", datadir, bpy_gethome(1), "bpydata/" );
+ if( BLI_exists( datadir ) )
+ ret = PyString_FromString( datadir );
+ else
+ ret = EXPP_incr_ret( Py_None );
+ }
+ else if(StringEqual(str, "udatadir")) {
+ char udatadir[FILE_MAXDIR];
- if( PyString_Check( object ) ) {
- str = PyString_AsString( object );
-
- if( StringEqual( str, "curframe" ) ) {
- return ( PyInt_FromLong( G.scene->r.cfra ) );
- }
- if( StringEqual( str, "curtime" ) ) {
- return ( PyFloat_FromDouble
- ( frame_to_float( G.scene->r.cfra ) ) );
- }
- if( StringEqual( str, "staframe" ) ) {
- return ( PyInt_FromLong( G.scene->r.sfra ) );
- }
- if( StringEqual( str, "endframe" ) ) {
- return ( PyInt_FromLong( G.scene->r.efra ) );
- }
- if( StringEqual( str, "filename" ) ) {
- return ( PyString_FromString( G.sce ) );
- }
- if( StringEqual( str, "homedir" ) ) {
- if( BLI_exists( bpy_gethome() ))
- return PyString_FromString( bpy_gethome() );
- else
- return EXPP_incr_ret( Py_None );
+ if (BLI_exists(U.pythondir)) {
+ BLI_make_file_string("/", udatadir, U.pythondir, "bpydata/");
+ if (BLI_exists(udatadir))
+ ret = PyString_FromString(udatadir);
}
+ if (!ret) ret = EXPP_incr_ret(Py_None);
+ }
+ else if( StringEqual( str, "scriptsdir" ) ) {
+ char *sdir = bpy_gethome(1);
- if( StringEqual( str, "datadir" ) ) {
- char datadir[FILE_MAXDIR];
- BLI_make_file_string( "/", datadir, bpy_gethome( ),
- "bpydata/" );
- if( BLI_exists( datadir ) )
- return PyString_FromString( datadir );
+ if (sdir)
+ ret = PyString_FromString(sdir);
else
- return EXPP_incr_ret( Py_None );
- }
- if( StringEqual( str, "scriptsdir" ) ) {
- char scriptsdir[FILE_MAXDIR];
- BLI_make_file_string( "/", scriptsdir, bpy_gethome( ),
- "scripts/" );
- if( BLI_exists( scriptsdir ) )
- return PyString_FromString( scriptsdir );
- else
- return EXPP_incr_ret( Py_None );
- }
- if( StringEqual( str, "uscriptsdir" ) ) {
+ ret = EXPP_incr_ret( Py_None );
+ }
+ else if( StringEqual( str, "uscriptsdir" ) ) {
if( BLI_exists( U.pythondir ) )
- return PyString_FromString( U.pythondir );
+ ret = PyString_FromString( U.pythondir );
else
- return EXPP_incr_ret( Py_None );
- }
- /* According to the old file (opy_blender.c), the following if
- statement is a quick hack and needs some clean up. */
- if( StringEqual( str, "vrmloptions" ) ) {
- dict = PyDict_New( );
-
- PyDict_SetItemString( dict, "twoside",
- PyInt_FromLong( U.
- vrmlflag &
- USER_VRML_TWOSIDED ) );
-
- PyDict_SetItemString( dict, "layers",
- PyInt_FromLong( U.
- vrmlflag &
- USER_VRML_LAYERS ) );
-
- PyDict_SetItemString( dict, "autoscale",
- PyInt_FromLong( U.
- vrmlflag &
- USER_VRML_AUTOSCALE ) );
-
- return ( dict );
- } /* End 'quick hack' part. */
- if( StringEqual( str, "version" ) ) {
- return ( PyInt_FromLong( G.version ) );
- }
- /* TODO: Do we want to display a usefull message here that the
- requested data is unknown?
- else
- {
- return (EXPP_ReturnPyObjError (..., "message") );
- }
- */
- } else {
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected string argument" ) );
+ ret = EXPP_incr_ret( Py_None );
}
+ /* According to the old file (opy_blender.c), the following if
+ statement is a quick hack and needs some clean up. */
+ else if( StringEqual( str, "vrmloptions" ) ) {
+ ret = PyDict_New( );
+
+ PyDict_SetItemString( dict, "twoside",
+ PyInt_FromLong( U.vrmlflag & USER_VRML_TWOSIDED ) );
- return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
- "bad request identifier" ) );
+ PyDict_SetItemString( dict, "layers",
+ PyInt_FromLong( U.vrmlflag & USER_VRML_LAYERS ) );
+
+ PyDict_SetItemString( dict, "autoscale",
+ PyInt_FromLong( U.vrmlflag & USER_VRML_AUTOSCALE ) );
+
+ } /* End 'quick hack' part. */
+ else if(StringEqual( str, "version" ))
+ ret = PyInt_FromLong( G.version );
+ else
+ return EXPP_ReturnPyObjError( PyExc_AttributeError, "unknown attribute" );
+
+ if (ret) return ret;
+ else
+ return EXPP_ReturnPyObjError (PyExc_MemoryError,
+ "could not create pystring!");
}
/*****************************************************************************/
@@ -491,6 +477,47 @@ static PyObject *Blender_Save( PyObject * self, PyObject * args )
return Py_None;
}
+static PyObject *Blender_Run(PyObject *self, PyObject *args)
+{
+ char *fname = NULL;
+ Text *text = NULL;
+ int is_blender_text = 0;
+
+ if (!PyArg_ParseTuple(args, "s", &fname))
+ return EXPP_ReturnPyObjError(PyExc_TypeError,
+ "expected a filename or a Blender Text name as argument");
+
+ if (!BLI_exists(fname)) { /* if there's no such filename ... */
+ text = G.main->text.first; /* try an already existing Blender Text */
+
+ while (text) {
+ if (!strcmp(fname, text->id.name + 2)) break;
+ text = text->id.next;
+ }
+
+ if (!text) {
+ return EXPP_ReturnPyObjError(PyExc_AttributeError,
+ "no such file or Blender text");
+ }
+ else is_blender_text = 1; /* fn is already a Blender Text */
+ }
+
+ else {
+ text = add_text(fname);
+
+ if (!text) {
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "couldn't create Blender Text from given file");
+ }
+ }
+
+ BPY_txt_do_python_Text(text);
+
+ if (!is_blender_text) free_libblock(&G.main->text, text);
+
+ return EXPP_incr_ret(Py_None);
+}
+
static PyObject * Blender_UpdateMenus( PyObject * self )
{
@@ -510,7 +537,7 @@ static PyObject * Blender_UpdateMenus( PyObject * self )
void M_Blender_Init( void )
{
PyObject *module;
- PyObject *dict;
+ PyObject *dict, *smode;
g_blenderdict = NULL;
@@ -519,12 +546,18 @@ void M_Blender_Init( void )
types_InitAll( ); /* set all our pytypes to &PyType_Type */
+ if (G.background)
+ smode = PyString_FromString("background");
+ else
+ smode = PyString_FromString("interactive");
+
dict = PyModule_GetDict( module );
g_blenderdict = dict;
PyDict_SetItemString( dict, "bylink", EXPP_incr_ret_False() );
PyDict_SetItemString( dict, "link", EXPP_incr_ret ( Py_None ) );
PyDict_SetItemString( dict, "event", PyString_FromString( "" ) );
+ PyDict_SetItemString( dict, "mode", smode );
PyDict_SetItemString( dict, "Types", Types_Init( ) );
PyDict_SetItemString( dict, "sys", sys_Init( ) );
diff --git a/source/blender/python/api2_2x/Ipo.c b/source/blender/python/api2_2x/Ipo.c
index 80a0a39ef5f..13f4229df5c 100644
--- a/source/blender/python/api2_2x/Ipo.c
+++ b/source/blender/python/api2_2x/Ipo.c
@@ -1119,7 +1119,7 @@ static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
"blender could not create ipo curve" );
allspace( REMAKEIPO, 0 );
- allqueue( REDRAWIPO, 0 );
+ EXPP_allqueue( REDRAWIPO, 0 );
/* create a bpy wrapper for the new ipo curve */
return IpoCurve_CreatePyObject( icu );
diff --git a/source/blender/python/api2_2x/NMesh.c b/source/blender/python/api2_2x/NMesh.c
index b1173799aa8..583a74e49a5 100644
--- a/source/blender/python/api2_2x/NMesh.c
+++ b/source/blender/python/api2_2x/NMesh.c
@@ -90,10 +90,8 @@
static PyObject *g_nmeshmodule = NULL;
static int unlink_existingMeshData( Mesh * mesh );
-static int convert_NMeshToMesh( Mesh * mesh, BPy_NMesh * nmesh, int store_edges );
-/* <start> */
+static int convert_NMeshToMesh( Mesh *mesh, BPy_NMesh *nmesh, int store_edges );
static PyObject *NMesh_printDebug( PyObject * self );
-/* <end> */
static PyObject *NMesh_addEdge( PyObject * self, PyObject * args );
static PyObject *NMesh_findEdge( PyObject * self, PyObject * args );
static PyObject *NMesh_removeEdge( PyObject * self, PyObject * args );
@@ -103,19 +101,15 @@ static PyObject *NMesh_removeFace( PyObject * self, PyObject * args );
static PyObject *NMesh_addVertGroup( PyObject * self, PyObject * args );
static PyObject *NMesh_removeVertGroup( PyObject * self, PyObject * args );
static PyObject *NMesh_assignVertsToGroup( PyObject * self, PyObject * args );
-static PyObject *NMesh_removeVertsFromGroup( PyObject * self,
- PyObject * args );
+static PyObject *NMesh_removeVertsFromGroup( PyObject * self,PyObject * args );
static PyObject *NMesh_getVertsFromGroup( PyObject * self, PyObject * args );
static PyObject *NMesh_renameVertGroup( PyObject * self, PyObject * args );
static PyObject *NMesh_getVertGroupNames( PyObject * self );
-
-/* <start> */
+static PyObject *NMesh_transform (PyObject *self, PyObject *args);
static char NMesh_printDebug_doc[] =
"print debug info about the mesh.";
-/* <end> */
-
static char NMesh_addEdge_doc[] =
"create an edge between two vertices.\n\
If an edge already exists between those vertices, it is returned.\n\
@@ -243,8 +237,7 @@ static char NMesh_getVertexInfluences_doc[] =
specified by index. The list contains pairs with the \n\
bone name and the weight.";
-
-static char NMesh_update_doc[] = \
+static char NMesh_update_doc[] =
"(recalc_normals = 0, store_edges = 0, vertex_shade = 0) - Updates the Mesh.\n\
Optional arguments: if given and nonzero:\n\
'recalc_normals': normal vectors are recalculated;\n\
@@ -288,14 +281,20 @@ This returns the mesh as used by the object, which\n\
means it contains all deformations and modifications.";
static char M_NMesh_PutRaw_doc[] =
- "(mesh, [name, renormal, store_edges]) - Return a raw mesh to Blender\n\n\
+ "(mesh, name = None, recalc_normals = 1, store_edges = 0]) -\n\
+Return a raw mesh to Blender\n\n\
(mesh) The NMesh object to store\n\
[name] The mesh to replace\n\
-[renormal=1] Flag to control vertex normal recalculation\n\
+[recalc_normals = 1] Flag to control vertex normal recalculation\n\
[store_edges=0] Store edges data in the blender mesh\n\
If the name of a mesh to replace is not given a new\n\
object is created and returned.";
+static char NMesh_transform_doc[] =
+ "(matrix, recalc_normals = 0) - Transform the mesh by the supplied 4x4\n\
+matrix.\n\
+(recalc_normals) - if given and 1 or True, transforming the vertex normals\n\
+is skipped.";
void mesh_update( Mesh * mesh )
@@ -1341,7 +1340,7 @@ static PyObject *NMesh_update( PyObject *self, PyObject *a, PyObject *kwd )
}
if( !during_script( ) && needs_redraw)
- allqueue( REDRAWVIEW3D, 0 );
+ EXPP_allqueue( REDRAWVIEW3D, 0 );
return PyInt_FromLong( 1 );
}
@@ -1579,6 +1578,7 @@ static struct PyMethodDef NMesh_methods[] = {
MethodDef( setMode ),
MethodDef( setMaxSmoothAngle ),
MethodDef( setSubDivLevels ),
+ MethodDef( transform ),
/* METH_NOARGS: function(PyObject *self) */
#undef MethodDef
@@ -2818,7 +2818,7 @@ static PyObject *M_NMesh_PutRaw( PyObject * self, PyObject * args )
mesh_update( mesh );
if( !during_script( ) )
- allqueue( REDRAWVIEW3D, 0 );
+ EXPP_allqueue( REDRAWVIEW3D, 0 );
// @OK...this requires some explanation:
// Materials can be assigned two ways:
@@ -3347,9 +3347,6 @@ static PyObject *NMesh_removeFace( PyObject * self, PyObject * args )
return EXPP_incr_ret( Py_None );
}
-
-/* <start> */
-
static PyObject *NMesh_printDebug( PyObject * self )
{
BPy_NMesh *bmesh=(BPy_NMesh *)self;
@@ -3402,7 +3399,6 @@ static PyObject *NMesh_printDebug( PyObject * self )
return EXPP_incr_ret( Py_None );
}
-/* <end> */
static PyObject *NMesh_addVertGroup( PyObject * self, PyObject * args )
{
char *groupStr;
@@ -3425,7 +3421,7 @@ static PyObject *NMesh_addVertGroup( PyObject * self, PyObject * args )
add_defgroup_name( object, groupStr );
- allqueue( REDRAWBUTSALL, 1 );
+ EXPP_allqueue( REDRAWBUTSALL, 1 );
return EXPP_incr_ret( Py_None );
}
@@ -3461,7 +3457,7 @@ static PyObject *NMesh_removeVertGroup( PyObject * self, PyObject * args )
del_defgroup( object );
- allqueue( REDRAWBUTSALL, 1 );
+ EXPP_allqueue( REDRAWBUTSALL, 1 );
return EXPP_incr_ret( Py_None );
}
@@ -3658,7 +3654,7 @@ static PyObject *NMesh_getVertsFromGroup( PyObject * self, PyObject * args )
int tempInt;
int x;
- listObject = ( void * ) -2054456; //can't use NULL macro because compiler thinks
+ listObject = Py_None; //can't use NULL macro because compiler thinks
//it's a 0 and we need to check 0 index vertex pos
l1 = FALSE;
l2 = FALSE;
@@ -3705,7 +3701,7 @@ static PyObject *NMesh_getVertsFromGroup( PyObject * self, PyObject * args )
count = 0;
- if( listObject == ( void * ) -2054456 ) //do entire group
+ if( listObject == Py_None ) //do entire group
{
for( k = 0; k < ( ( Mesh * ) object->data )->totvert; k++ ) {
dvert = ( ( Mesh * ) object->data )->dvert + k;
@@ -3816,14 +3812,12 @@ static PyObject *NMesh_renameVertGroup( PyObject * self, PyObject * args )
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
"Couldn't find the expected vertex group" );
- //set name
PyOS_snprintf( defGroup->name, 32, newGr );
unique_vertexgroup_name( defGroup, ( ( BPy_NMesh * ) self )->object );
return EXPP_incr_ret( Py_None );
}
-
static PyObject *NMesh_getVertGroupNames( PyObject * self )
{
bDeformGroup *defGroup;
@@ -3844,3 +3838,74 @@ static PyObject *NMesh_getVertGroupNames( PyObject * self )
return list;
}
+
+static PyObject *NMesh_transform (PyObject *self, PyObject *args)
+{
+ BPy_NMesh *nmesh = ( BPy_NMesh * ) self;
+ BPy_NMVert *mv;
+ PyObject *ob1 = NULL;
+ MatrixObject *mat;
+ float vx, vy, vz;
+ int i, recalc_normals = 0;
+
+ if( !PyArg_ParseTuple( args, "O!|i", &matrix_Type, &ob1, &recalc_normals ) )
+ return ( EXPP_ReturnPyObjError( PyExc_TypeError,
+ "expected matrix and optionally an int as arguments" ) );
+
+ mat = ( MatrixObject * ) ob1;
+
+ if( mat->colSize != 4 || mat->rowSize != 4 )
+ return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
+ "matrix must be a 4x4 transformation matrix\n"
+ "for example as returned by object.getMatrix()" ) );
+
+ /* loop through all the verts and transform locations by the supplied
+ * matrix */
+ for( i = 0; i < PySequence_Length(nmesh->verts); i++ ) {
+ mv = ( BPy_NMVert * ) PySequence_GetItem( nmesh->verts, i );
+ vx = mv->co[0];
+ vy = mv->co[1];
+ vz = mv->co[2];
+
+ /* Mat4MulVecfl(mat->matrix, mv->co); */
+
+ mv->co[0] = vx*mat->matrix[0][0] + vy*mat->matrix[1][0] +
+ vz*mat->matrix[2][0] + mat->matrix[3][0];
+ mv->co[1] = vx*mat->matrix[0][1] + vy*mat->matrix[1][1] +
+ vz*mat->matrix[2][1] + mat->matrix[3][1];
+ mv->co[2] = vx*mat->matrix[0][2] + vy*mat->matrix[1][2] +
+ vz*mat->matrix[2][2] + mat->matrix[3][2];
+
+ Py_DECREF(mv);
+ }
+
+ if ( recalc_normals ) {
+ /* loop through all the verts and transform normals by the inverse
+ * of the transpose of the supplied matrix */
+ float invmat[4][4];
+
+ if (!Mat4Invert(invmat, mat->matrix))
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "given matrix is not invertible");
+
+ for( i = 0; i < PySequence_Length(nmesh->verts); i++ ) {
+ mv = ( BPy_NMVert * ) PySequence_GetItem( nmesh->verts, i );
+ vx = mv->no[0];
+ vy = mv->no[1];
+ vz = mv->no[2];
+ mv->no[0] = vx*invmat[0][0] + vy*invmat[0][1] + vz*invmat[0][2] +
+ invmat[0][3];
+ mv->no[1] = vx*invmat[1][0] + vy*invmat[1][1] + vz*invmat[1][2] +
+ invmat[1][3];
+ mv->no[2] = vx*invmat[2][0] + vy*invmat[2][1] + vz*invmat[2][2] +
+ invmat[2][3];
+ Normalise(mv->no);
+ Py_DECREF(mv);
+ }
+ }
+
+ /* should we alternatively return a list of changed verts (and preserve
+ * the original ones) ? */
+ Py_INCREF( Py_None );
+ return Py_None;
+}
diff --git a/source/blender/python/api2_2x/Sound.c b/source/blender/python/api2_2x/Sound.c
index 86857ee453b..8ba3bd23b81 100644
--- a/source/blender/python/api2_2x/Sound.c
+++ b/source/blender/python/api2_2x/Sound.c
@@ -36,7 +36,7 @@
#include <BKE_sound.h>
#include <BLI_blenlib.h>
#include <BIF_editsound.h>
-#include <BIF_space.h> /* allqueue() */
+#include <BIF_space.h> /* EXPP_allqueue() */
#include "mydevice.h" /* redraw defines */
@@ -427,8 +427,8 @@ static PyObject *Sound_setCurrent( BPy_Sound * self )
}
}
- allqueue( REDRAWSOUND, 0 );
- allqueue( REDRAWBUTSLOGIC, 0 );
+ EXPP_allqueue( REDRAWSOUND, 0 );
+ EXPP_allqueue( REDRAWBUTSLOGIC, 0 );
Py_INCREF( Py_None );
return Py_None;
diff --git a/source/blender/python/api2_2x/Text.c b/source/blender/python/api2_2x/Text.c
index 55304588515..90de9b5bed1 100644
--- a/source/blender/python/api2_2x/Text.c
+++ b/source/blender/python/api2_2x/Text.c
@@ -40,6 +40,7 @@
#include <BIF_drawtext.h>
#include <BKE_text.h>
#include <BLI_blenlib.h>
+#include <DNA_space_types.h>
#include <DNA_text_types.h>
#include "Text.h"
@@ -51,8 +52,7 @@
/*****************************************************************************/
/* Python API function prototypes for the Text module. */
/*****************************************************************************/
-static PyObject *M_Text_New( PyObject * self, PyObject * args,
- PyObject * keywords );
+static PyObject *M_Text_New( PyObject * self, PyObject * args);
static PyObject *M_Text_Get( PyObject * self, PyObject * args );
static PyObject *M_Text_Load( PyObject * self, PyObject * args );
static PyObject *M_Text_unlink( PyObject * self, PyObject * args );
@@ -81,8 +81,7 @@ static char M_Text_unlink_doc[] =
/* Python method structure definition for Blender.Text module: */
/*****************************************************************************/
struct PyMethodDef M_Text_methods[] = {
- {"New", ( PyCFunction ) M_Text_New, METH_VARARGS | METH_KEYWORDS,
- M_Text_New_doc},
+ {"New", M_Text_New, METH_VARARGS, M_Text_New_doc},
{"Get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
{"get", M_Text_Get, METH_VARARGS, M_Text_Get_doc},
{"Load", M_Text_Load, METH_VARARGS, M_Text_Load_doc},
@@ -107,10 +106,10 @@ static PyObject *Text_getName( BPy_Text * self );
static PyObject *Text_getFilename( BPy_Text * self );
static PyObject *Text_getNLines( BPy_Text * self );
static PyObject *Text_setName( BPy_Text * self, PyObject * args );
-static PyObject *Text_clear( BPy_Text * self, PyObject * args );
+static PyObject *Text_clear( BPy_Text * self );
static PyObject *Text_write( BPy_Text * self, PyObject * args );
static PyObject *Text_set( BPy_Text * self, PyObject * args );
-static PyObject *Text_asLines( BPy_Text * self, PyObject * args );
+static PyObject *Text_asLines( BPy_Text * self );
/*****************************************************************************/
/* Python BPy_Text methods table: */
@@ -125,13 +124,13 @@ static PyMethodDef BPy_Text_methods[] = {
"() - Return number of lines in text buffer"},
{"setName", ( PyCFunction ) Text_setName, METH_VARARGS,
"(str) - Change Text Object name"},
- {"clear", ( PyCFunction ) Text_clear, METH_VARARGS,
+ {"clear", ( PyCFunction ) Text_clear, METH_NOARGS,
"() - Clear Text buffer"},
{"write", ( PyCFunction ) Text_write, METH_VARARGS,
"(line) - Append string 'str' to Text buffer"},
{"set", ( PyCFunction ) Text_set, METH_VARARGS,
"(name, val) - Set attribute 'name' to value 'val'"},
- {"asLines", ( PyCFunction ) Text_asLines, METH_VARARGS,
+ {"asLines", ( PyCFunction ) Text_asLines, METH_NOARGS,
"() - Return text buffer as a list of lines"},
{NULL, NULL, 0, NULL}
};
@@ -170,14 +169,14 @@ PyTypeObject Text_Type = {
0, 0, 0, 0, 0, 0,
BPy_Text_methods, /* tp_methods */
0, /* tp_members */
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
/*****************************************************************************/
/* Function: M_Text_New */
/* Python equivalent: Blender.Text.New */
/*****************************************************************************/
-static PyObject *M_Text_New( PyObject * self, PyObject * args,
- PyObject * keywords )
+static PyObject *M_Text_New( PyObject * self, PyObject * args)
{
char *name = NULL;
char buf[21];
@@ -249,9 +248,9 @@ static PyObject *M_Text_Get( PyObject * self, PyObject * args )
if( wanted_txt == NULL ) { /* Requested text doesn't exist */
char error_msg[64];
PyOS_snprintf( error_msg, sizeof( error_msg ),
- "Text \"%s\" not found", name );
+ "Text \"%s\" not found", name );
return ( EXPP_ReturnPyObjError
- ( PyExc_NameError, error_msg ) );
+ ( PyExc_NameError, error_msg ) );
}
return wanted_txt;
@@ -293,28 +292,30 @@ static PyObject *M_Text_Get( PyObject * self, PyObject * args )
/*****************************************************************************/
static PyObject *M_Text_Load( PyObject * self, PyObject * args )
{
- char *fname;
- Text *txt_ptr;
- BPy_Text *txt;
+ char *fname = NULL;
+ char fpath[FILE_MAXDIR + FILE_MAXFILE];
+ Text *txt_ptr = NULL;
+ unsigned int maxlen = FILE_MAXDIR + FILE_MAXFILE;
if( !PyArg_ParseTuple( args, "s", &fname ) )
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
"expected string argument" ) );
- txt = ( BPy_Text * ) PyObject_NEW( BPy_Text, &Text_Type );
+ if (strlen(fname) > (maxlen - 1))
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "text filename too long");
+ else if (!BLI_exists(fname))
+ return EXPP_ReturnPyObjError (PyExc_AttributeError,
+ "text file not found");
- if( !txt )
- return EXPP_ReturnPyObjError( PyExc_MemoryError,
- "couldn't create PyObject Text_Type" );
+ BLI_strncpy(fpath, fname, maxlen);
- txt_ptr = add_text( fname );
+ txt_ptr = add_text( fpath );
if( !txt_ptr )
return EXPP_ReturnPyObjError( PyExc_IOError,
"couldn't load text" );
- txt->text = txt_ptr;
-
- return ( PyObject * ) txt;
+ return Text_CreatePyObject(txt_ptr);
}
/*****************************************************************************/
@@ -454,7 +455,7 @@ static PyObject *Text_setName( BPy_Text * self, PyObject * args )
return Py_None;
}
-static PyObject *Text_clear( BPy_Text * self, PyObject * args )
+static PyObject *Text_clear( BPy_Text * self)
{
int oldstate;
@@ -514,7 +515,7 @@ static PyObject *Text_write( BPy_Text * self, PyObject * args )
return Py_None;
}
-static PyObject *Text_asLines( BPy_Text * self, PyObject * args )
+static PyObject *Text_asLines( BPy_Text * self )
{
TextLine *line;
PyObject *list, *ob;
diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c
index 9543bdd2034..b8998a943ac 100644
--- a/source/blender/python/api2_2x/Window.c
+++ b/source/blender/python/api2_2x/Window.c
@@ -37,7 +37,7 @@
#include <BDR_editobject.h> /* enter / leave editmode */
#include <BKE_global.h>
#include <BKE_library.h>
-#include <BKE_object.h> /* for during_script() */
+#include <BKE_object.h> /* for during_script() and during_scriptlink() */
#include <BKE_scene.h> /* scene_find_camera() */
#include <BIF_usiblender.h>
#include <BIF_mywindow.h>
@@ -378,7 +378,7 @@ PyObject *M_Window_Redraw( PyObject * self, PyObject * args )
if( wintype < 0 )
redraw_all = 1;
- if( !during_script( ) ) {
+ if( !during_script( ) && !G.background ) {
tempsa = curarea;
sa = G.curscreen->areabase.first;
@@ -432,7 +432,7 @@ static PyObject *M_Window_RedrawAll( PyObject * self, PyObject * args )
/*****************************************************************************/
static PyObject *M_Window_QRedrawAll( PyObject * self, PyObject * args )
{
- allqueue( REDRAWALL, 0 );
+ EXPP_allqueue( REDRAWALL, 0 );
Py_INCREF( Py_None );
return Py_None;
@@ -478,11 +478,20 @@ static PyObject *M_Window_FileSelector( PyObject * self, PyObject * args )
Script *script = NULL;
int startspace = 0;
- if( (!PyArg_ParseTuple( args, "O|ss", &EXPP_FS_PyCallback, &title, &filename ) )
+ if (during_scriptlink())
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "script links can't call the file selector");
+
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "the file selector is not available in background mode");
+
+ if((!PyArg_ParseTuple( args, "O|ss", &EXPP_FS_PyCallback, &title, &filename))
|| (!PyCallable_Check(EXPP_FS_PyCallback)))
return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "\nexpected a callback function (and optionally one or two strings) "
- "as argument(s)" );
+ "\nexpected a callback function (and optionally one or two strings) "
+ "as argument(s)" );
+
Py_XINCREF(EXPP_FS_PyCallback);
/* trick: we move to a spacescript because then the fileselector will properly
@@ -528,12 +537,21 @@ static PyObject *M_Window_ImageSelector( PyObject * self, PyObject * args )
Script *script = NULL;
int startspace = 0;
+ if (during_scriptlink())
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "script links can't call the image selector");
+
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "the image selector is not available in background mode");
+
if( !PyArg_ParseTuple( args, "O|ss", &EXPP_FS_PyCallback, &title, &filename )
|| (!PyCallable_Check(EXPP_FS_PyCallback)))
return ( EXPP_ReturnPyObjError
( PyExc_AttributeError,
"\nexpected a callback function (and optionally one or two strings) "
"as argument(s)" ) );
+
Py_XINCREF(EXPP_FS_PyCallback);
/* trick: we move to a spacescript because then the fileselector will properly
@@ -581,6 +599,10 @@ static PyObject *M_Window_DrawProgressBar( PyObject * self, PyObject * args )
char *info = NULL;
int retval = 0;
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "the progress bar is not available in background mode");
+
if( !PyArg_ParseTuple( args, "fs", &done, &info ) )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected a float and a string as arguments" ) );
@@ -964,6 +986,10 @@ static PyObject *M_Window_QRead( PyObject * self )
short val = 0;
unsigned short event;
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "QRead is not available in background mode");
+
event = extern_qread( &val );
return Py_BuildValue( "ii", event, val );
@@ -976,6 +1002,10 @@ static PyObject *M_Window_QAdd( PyObject * self, PyObject * args )
short val;
short after = 0;
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "QAdd is not available in background mode");
+
if( !PyArg_ParseTuple( args, "hhh|h", &win, &evt, &val, &after ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected three or four ints as arguments" );
@@ -998,6 +1028,10 @@ static PyObject *M_Window_QHandle( PyObject * self, PyObject * args )
ScrArea *sa = G.curscreen->areabase.first;
ScrArea *oldsa = NULL;
+ if (G.background)
+ return EXPP_ReturnPyObjError(PyExc_RuntimeError,
+ "QHandle is not available in background mode");
+
if( !PyArg_ParseTuple( args, "h", &win ) )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected an int as argument" );
@@ -1153,7 +1187,7 @@ static PyObject *M_Window_SetScreen( PyObject * self, PyObject * args )
if( !scr )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "no such screen, check Window.GetScreens() for valid names." );
+ "no such screen, check Window.GetScreens() for valid names" );
return EXPP_incr_ret( Py_None );
}
diff --git a/source/blender/python/api2_2x/doc/API_intro.py b/source/blender/python/api2_2x/doc/API_intro.py
index 1c910711d46..8f4031756f2 100644
--- a/source/blender/python/api2_2x/doc/API_intro.py
+++ b/source/blender/python/api2_2x/doc/API_intro.py
@@ -67,22 +67,29 @@ Introduction:
Scripting and Blender:
======================
-There are four basic ways to execute scripts in Blender:
+These are the basic ways to execute scripts in Blender:
1. They can be loaded or typed as text files in the Text Editor window, then
executed with ALT+P.
- 2. Via command line: 'blender -P <scriptname>' will start Blender and executed
+ 2. Via command line: C{blender -P <scriptname>} will start Blender and execute
the given script. <scriptname> can be a filename in the user's file system or
the name of a text saved in a .blend Blender file:
'blender myfile.blend -P textname'.
- 3. Properly registered scripts can be selected directly from the program's
+ 3. Via command line in I{background mode}: use the '-b' flag (the order is
+ important): C{blender -b <blendfile> -P <scriptname>}. <blendfile> can be any
+ .blend file, including the default .B.blend that is in Blender's home dir
+ L{Blender.Get}('homedir'). In this mode no window will be opened and the
+ program will leave as soon as the script finishes execution.
+ 4. Properly registered scripts can be selected directly from the program's
menus.
- 4. Scriptlinks: these are also loaded or typed in the Text Editor window and
+ 5. Scriptlinks: these are also loaded or typed in the Text Editor window and
can be linked to objects, materials or scenes using the Scriptlink buttons
tab. Script links get executed automatically when their events (ONLOAD,
REDRAW, FRAMECHANGED) are triggered. Normal scripts can create (L{Text}) and
link other scripts to objects and events, see L{Object.Object.addScriptLink},
for example.
+ 6. A script can call another script (that will run in its own context, with
+ its own global dictionary) with the L{Blender.Run} module function.
Registering scripts:
--------------------
@@ -148,6 +155,7 @@ Interaction with users:
program buttons, which stay there accepting user input like any other
Blender window until the user closes them;
- make changes to the 3D View (set visible layer(s), view point, etc);
+ - tell Blender to execute other scripts (see L{Blender.Run}());
- use external Python libraries, if available.
You can read the documentation for the L{Window}, L{Draw} and L{BGL} modules
@@ -161,16 +169,56 @@ Command line mode:
Python was embedded in Blender, so to access bpython modules you need to
run scripts from the program itself: you can't import the Blender module
- into an external Python interpreter. But with "OnLoad" script links, the
- "-b" background mode and additions like the "-P" command line switch,
- L{Blender.Save}, L{Blender.Load}, L{Blender.Quit} and the L{Library} module,
- for many tasks it's possible to control Blender via some automated process
- using scripts. Note that command line scripts are run before Blender
- initializes its windows, so many functions that get or set window related
- attributes (like most in L{Window}) don't work here. If you need those, use
- an ONLOAD script link (see L{Scene.Scene.addScriptLink}) instead -- it's
- also possible to use a command line script to write or set an ONLOAD script
- link.
+ into an external Python interpreter.
+
+ But with "OnLoad" script links, the "-b" background mode and additions like
+ the "-P" command line switch, L{Blender.Save}, L{Blender.Load},
+ L{Blender.Quit} and the L{Library} module, for many tasks it's possible to
+ control Blender via some automated process using scripts. Note that command
+ line scripts are run before Blender initializes its windows (and in '-b' mode
+ no window will be initialized), so many functions that get or set window
+ related attributes (like most in L{Window}) don't work here. If you need
+ those, use an ONLOAD script link (see L{Scene.Scene.addScriptLink}) instead --
+ it's also possible to use a command line script to write or set an ONLOAD
+ script link. Check the L{Blender.mode} module var to know if Blender is being
+ executed in "background" or "interactive" mode.
+
+ Background mode examples::
+
+ # Open Blender in background mode with file 'myfile.blend'
+ # and run the script 'script.py':
+
+ blender -b myfile.blend -P script.py
+
+ # Note: a .blend file is always required. 'script.py' can be a file
+ # in the file system or a Blender Text stored in 'myfile.blend'.
+
+ # Let's assume 'script.py' has code to render the current frame;
+ # this line will set the [s]tart and [e]nd (and so the current) frame to
+ # frame 44 and call the script:
+
+ blender -b myfile.blend -s 44 -e 44 -P script.py
+
+ # Using now a script written to render animations, we set different
+ # start and end frames and then execute this line:
+
+ blender -b myfile.blend -s 1 -e 10 -P script.py
+
+ # Note: we can also set frames and define if we want a single image or
+ # an animation in the script body itself, naturally.
+
+ The rendered pictures will be written to the default render folder, that can
+ also be set via bpython (take a look at L{Render.RenderData}). Their
+ names will be the equivalent frame number followed by the extension of the
+ chosen image type: 0001.png, for example. To rename them to something else,
+ coders can use the C{rename} function in the standard 'os' Python module.
+
+ Reminder: if you just need to render, it's not necessary to have a script.
+ Blender can create stills and animations with its own command line arguments.
+ Example:
+ - a single image at frame 44: blender -b myfile.blend -f 44
+ - an animation from frame 1 to 10: blender -b myfile.blend -s 1 -e 10 -a
+
Demo mode:
----------
@@ -263,7 +311,7 @@ Documenting scripts:
Example::
__author__ = 'Mr. Author'
- __version__ = '1.0 11/11/04'
+ __version__ = '1.0 2005/06/06'
__url__ = ["Author's site, http://somewhere.com",
"Support forum, http://somewhere.com/forum/", "blender", "elysiun"]
__email__ = ["Mr. Author, mrauthor:somewhere*com", "scripts"]
@@ -294,9 +342,10 @@ A note to newbie script writers:
Interpreted languages are known to be much slower than compiled code, but for
many applications the difference is negligible or acceptable. Also, with
- profiling to identify slow areas and well thought optimizations, the speed
- can be I{considerably} improved in many cases. Try some of the best bpython
- scripts to get an idea of what can be done, you may be surprised.
+ profiling (or even simple direct timing with L{Blender.sys.time<Sys.time>}) to
+ identify slow areas and well thought optimizations, the speed can be
+ I{considerably} improved in many cases. Try some of the best bpython scripts
+ to get an idea of what can be done, you may be surprised.
@author: The Blender Python Team
@requires: Blender 2.35 or newer.
diff --git a/source/blender/python/api2_2x/doc/Blender.py b/source/blender/python/api2_2x/doc/Blender.py
index 14ca8e8505d..d22536c24a8 100644
--- a/source/blender/python/api2_2x/doc/Blender.py
+++ b/source/blender/python/api2_2x/doc/Blender.py
@@ -10,10 +10,27 @@
"""
The main Blender module.
-B{New}: L{UpdateMenus}.
+B{New}: L{Run}, L{UpdateMenus}, new options to L{Get}.
Blender
=======
+
+@type bylink: bool
+@var bylink: True if the current script is being executed as a script link.
+@type link: Blender Object or None
+@var link: if this script is a running script link, 'link' points to the
+ linked Object (can be a scene, object (mesh, camera, lamp), material or
+ world). If this is not a script link, 'link' is None.
+@type event: string
+@var event: if this script is a running script link, 'event' tells what
+ kind of link triggered it (ex: OnLoad, FrameChanged, Redraw, etc.).
+@type mode: string
+@var mode: Blender's current mode:
+ - 'interactive': normal mode, with an open window answering to user input;
+ - 'background': Blender was started as 'C{blender -b <blender file>}' and
+ will exit as soon as it finishes rendering or executing a script
+ (ex: 'C{blender -b <blender file> -P <script>}'). Try 'C{blender -h}'
+ for more detailed informations.
"""
def Set (request, data):
@@ -31,21 +48,25 @@ def Get (request):
Retrieve settings from Blender.
@type request: string
@param request: The setting data to be returned:
- - 'curframe': the current animation frame
- - 'curtime' : the current animation time
- - 'staframe': the start frame of the animation
- - 'endframe': the end frame of the animation
- - 'filename': the name of the last file read or written
- - 'homedir': Blender's home dir
+ - 'curframe': the current animation frame.
+ - 'curtime' : the current animation time.
+ - 'staframe': the start frame of the animation.
+ - 'endframe': the end frame of the animation.
+ - 'filename': the name of the last file read or written.
+ - 'homedir': Blender's home dir.
- 'datadir' : the path to the dir where scripts should store and
retrieve their data files, including saved configuration (can
be None, if not found).
+ - 'udatadir': the path to the user defined data dir. This may not be
+ available (is None if not found), but users that define uscriptsdir
+ have a place for their own scripts and script data that won't be
+ erased when a new version of Blender is installed.
- 'scriptsdir': the path to the main dir where scripts are stored
(can be None, if not found).
- 'uscriptsdir': the path to the user defined dir for scripts, see
the paths tab in the User Preferences window in Blender
(can be None, if not found).
- - 'version' : the Blender version number
+ - 'version' : the Blender version number.
@return: The requested data.
"""
@@ -108,6 +129,17 @@ def Save (filename, overwrite = 0):
@note: DXF, STL and Videoscape export only B{selected} meshes.
"""
+def Run (script):
+ """
+ Execute the given script.
+ @type script: string
+ @param script: the name of an available Blender Text (use L{Text.Get}() to
+ get a complete list) or the full pathname to a Python script file in the
+ system.
+ @note: the script is executed in its own context (with its own global
+ dictionary), as if you had called it with ALT+P or chosen from a menu.
+ """
+
def UpdateMenus ():
"""
Update the menus that list registered scripts. This will scan the default
diff --git a/source/blender/python/api2_2x/doc/NMesh.py b/source/blender/python/api2_2x/doc/NMesh.py
index 07c86cbbf55..8b5be59b38f 100644
--- a/source/blender/python/api2_2x/doc/NMesh.py
+++ b/source/blender/python/api2_2x/doc/NMesh.py
@@ -4,7 +4,8 @@
The Blender.NMesh submodule.
B{New}: edges class (L{NMEdge}) and nmesh methods (L{NMesh.addEdge},
-L{NMesh.addEdgesData}, etc.); new optional arguments to L{NMesh.update}.
+L{NMesh.addEdgesData}, etc.); new optional arguments to L{NMesh.update};
+L{NMesh.transform}.
Mesh Data
=========
@@ -154,16 +155,16 @@ def GetRawFromObject(name):
be created.
"""
-def PutRaw(nmesh, name = None, recalculate_normals = 1, store_edges = 0):
+def PutRaw(nmesh, name = None, recalc_normals = 1, store_edges = 0):
"""
Put an NMesh object back in Blender.
@type nmesh: NMesh
@type name: string
- @type recalculate_normals: int
+ @type recalc_normals: int
@type store_edges: int
@param name: The name of the mesh data object in Blender which will receive
this nmesh data. It can be an existing mesh data object or a new one.
- @param recalculate_normals: If non-zero, the vertex normals for the mesh will
+ @param recalc_normals: If non-zero, the vertex normals for the mesh will
be recalculated.
@param store_edges: if non-zero, the edges data are stored
@rtype: None or Object
@@ -339,9 +340,10 @@ class NMesh:
def addEdge(v1, v2):
"""
Create an edge between two vertices.
- If an edge already exists between those vertices, it is returned. (in blender, only zero or one edge can link two vertices).
+ If an edge already exists between those vertices, it is returned.
Created edge is automatically added to edges list.
You can only call this method if mesh has edge data.
+ @note: In Blender only zero or one edge can link two vertices.
@type v1: NMVert
@param v1: the first vertex of the edge.
@type v2: NMVert
@@ -552,8 +554,10 @@ class NMesh:
@param store_edges: if nonzero, then edge data is stored.
@type vertex_shade: int (bool)
@param vertex_shade: if nonzero vertices are colored based on the
- current lighting setup. To use it, be out of edit mode or else
- an error will be returned.
+ current lighting setup, like when there are no vertex colors and no
+ textured faces and a user enters Vertex Paint Mode in Blender (only
+ lamps in visible layers account). To use this functionality, be out of
+ edit mode or else an error will be returned.
@warn: edit mesh and normal mesh are two different structures in Blender,
synchronized upon leaving or entering edit mode. Always remember to
leave edit mode (L{Window.EditMode}) before calling this update
@@ -568,6 +572,41 @@ class NMesh:
L{setMode}) need their display lists updated, too.
"""
+ def transform(matrix, recalc_normals = False):
+ """
+ Transforms the mesh by the specified 4x4 matrix, as returned by
+ L{Object.Object.getMatrix}, though this will work with any invertible 4x4
+ matrix type. Ideal Usage for this is exporting to an external file, where
+ global vertex locations are required for each object.
+ Sometimes external renderers / file formats do not use vertex normals.
+ In this case you can skip transforming the vertex normals by letting
+ the optional parameter recalc_normals as False or 0.
+
+ Example::
+ # This script outputs deformed meshes worldspace vertex locations
+ # for a selected object
+ import Blender
+ from Blender import NMesh, Object
+
+ ob = Object.GetSelected()[0] # Get the first selected object
+ me = NMesh.GetRawFromObject(ob) # Get the objects deformed mesh data
+ me.transform(ob.matrix)
+
+ for v in me.verts:
+ print 'worldspace vert', v.co
+
+ @type matrix: Py_Matrix
+ @param matrix: 4x4 Matrix which can contain location, scale and rotation.
+ @type recalc_normals: int (bool)
+ @param recalc_normals: if True or 1, will only transform vertex locations.
+ @warn: if you call this method and later L{update} the mesh, the new
+ vertex positions will be passed back to Blender, but the object
+ matrix of each object linked to this mesh won't be automatically
+ updated. You need to set the object transformations (rotation,
+ translation and scaling) to identities, then, or the mesh data will
+ be changed ("transformed twice").
+ """
+
def getMode():
"""
Get this mesh's mode flags.
diff --git a/source/blender/python/api2_2x/doc/Window.py b/source/blender/python/api2_2x/doc/Window.py
index e6a81e9afde..0b41a3038c7 100644
--- a/source/blender/python/api2_2x/doc/Window.py
+++ b/source/blender/python/api2_2x/doc/Window.py
@@ -8,8 +8,6 @@ Window
This module provides access to B{Window} functions in Blender.
-B{New}: L{GetPerspMatrix}.
-
Example:
--------
@@ -133,6 +131,11 @@ def FileSelector (callback, title = 'SELECT FILE', filename = '<default>'):
and return from the file selection window.
@type filename: string
@param filename: A filename. This defaults to Blender.Get('filename').
+ @warn: script links are not allowed to call the File / Image Selectors. This
+ is because script links global dictionaries are removed when they finish
+ execution and the File Selector needs the passed callback to stay around.
+ An alternative is calling the File Selector from another script (see
+ L{Blender.Run}).
"""
def ImageSelector (callback, title = 'SELECT IMAGE', filename = '<default>'):
@@ -153,7 +156,12 @@ def ImageSelector (callback, title = 'SELECT IMAGE', filename = '<default>'):
@param title: The string that appears in the button to confirm the selection
and return from the image selection window.
@type filename: string
- @param filename: A filename. This defaults to Blender.Get('filename').
+ @param filename: A filename. This defaults to L{Blender.Get}('filename').
+ @warn: script links are not allowed to call the File / Image Selectors. This
+ is because script links global dictionaries are removed when they finish
+ execution and the File Selector needs the passed callback to stay around.
+ An alternative is calling the File Selector from another script (see
+ L{Blender.Run}).
"""
def DrawProgressBar (done, text):
diff --git a/source/blender/python/api2_2x/gen_utils.c b/source/blender/python/api2_2x/gen_utils.c
index 685adb67b46..b8e8f92b83e 100644
--- a/source/blender/python/api2_2x/gen_utils.c
+++ b/source/blender/python/api2_2x/gen_utils.c
@@ -282,6 +282,14 @@ int EXPP_map_getStrVal( const EXPP_map_pair * map, int ival,
return 0;
}
+/* Redraw wrappers */
+
+/* this queues redraws if we're not in background mode: */
+void EXPP_allqueue(unsigned short event, short val)
+{
+ if (!G.background) allqueue(event, val);
+}
+
/************************************************************************/
/* Scriptlink-related functions, used by scene, object, etc. bpyobjects */
/************************************************************************/
diff --git a/source/blender/python/api2_2x/gen_utils.h b/source/blender/python/api2_2x/gen_utils.h
index 6baf76c9ee5..e2c1dfe82a0 100644
--- a/source/blender/python/api2_2x/gen_utils.h
+++ b/source/blender/python/api2_2x/gen_utils.h
@@ -94,4 +94,7 @@ PyObject *EXPP_getScriptLinks( ScriptLink * slink, PyObject * args,
int EXPP_clearScriptLinks( ScriptLink * slink );
int EXPP_addScriptLink( ScriptLink * slink, PyObject * args, int is_scene );
+/* this queues redraws if we're not in background mode: */
+void EXPP_allqueue(unsigned short event, short val);
+
#endif /* EXPP_gen_utils_h */
diff --git a/source/blender/python/api2_2x/sceneRender.c b/source/blender/python/api2_2x/sceneRender.c
index 70d0c676dcd..f5de8a1c4d5 100644
--- a/source/blender/python/api2_2x/sceneRender.c
+++ b/source/blender/python/api2_2x/sceneRender.c
@@ -43,6 +43,7 @@
#include <mydevice.h>
#include <butspace.h>
#include <BKE_bad_level_calls.h>
+#include <render.h> /* RE_animrender() */
#include "sceneRender.h"
#include "blendef.h"
#include "Scene.h"
@@ -524,6 +525,7 @@ PyTypeObject RenderData_Type = {
0, 0, 0, 0, 0, 0,
BPy_RenderData_methods, /* tp_methods */
0, /* tp_members */
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
//---------------------------------------------------Render Module Init--
PyObject *Render_Init( void )
@@ -639,7 +641,7 @@ static PyObject *M_Render_BitToggleInt( PyObject * args, int setting,
*structure |= setting;
else
*structure &= ~setting;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
@@ -665,7 +667,7 @@ static PyObject *M_Render_BitToggleShort( PyObject * args, short setting,
*structure |= setting;
else
*structure &= ~setting;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
@@ -692,7 +694,7 @@ static PyObject *M_Render_GetSetAttributeFloat( PyObject * args,
}
*structure = property;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
} else
return Py_BuildValue( "f", *structure );
@@ -719,7 +721,7 @@ static PyObject *M_Render_GetSetAttributeShort( PyObject * args,
}
*structure = property;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
} else
return Py_BuildValue( "h", *structure );
@@ -745,7 +747,7 @@ static PyObject *M_Render_GetSetAttributeInt( PyObject * args, int *structure,
}
*structure = property;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
} else
return Py_BuildValue( "i", *structure );
@@ -768,8 +770,8 @@ static void M_Render_DoSizePreset( BPy_RenderData * self, short xsch,
self->renderContext->yparts = yparts;
BLI_init_rctf( &self->renderContext->safety, a, b, c, d );
- allqueue( REDRAWBUTSSCENE, 0 );
- allqueue( REDRAWVIEWCAM, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWVIEWCAM, 0 );
}
//------------------------------------Render Module Function Definitions-
@@ -819,7 +821,7 @@ PyObject *M_Render_SetRenderWinPos( PyObject * self, PyObject * args )
return EXPP_ReturnPyObjError( PyExc_AttributeError,
"list contains unknown string\n" );
}
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -828,7 +830,7 @@ PyObject *M_Render_SetRenderWinPos( PyObject * self, PyObject * args )
PyObject *M_Render_EnableDispView( PyObject * self )
{
G.displaymode = R_DISPLAYVIEW;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -837,7 +839,7 @@ PyObject *M_Render_EnableDispView( PyObject * self )
PyObject *M_Render_EnableDispWin( PyObject * self )
{
G.displaymode = R_DISPLAYWIN;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -861,10 +863,28 @@ PyObject *RenderData_Render( BPy_RenderData * self )
{
Scene *oldsce;
- oldsce = G.scene;
- set_scene( self->scene );
- BIF_do_render( 0 );
- set_scene( oldsce );
+ if (!G.background) {
+ oldsce = G.scene;
+ set_scene( self->scene );
+ BIF_do_render( 0 );
+ set_scene( oldsce );
+ }
+
+ else { /* background mode (blender -b file.blend -P script) */
+
+ int end_frame = G.scene->r.efra; /* is of type short currently */
+
+ if (G.scene != self->scene)
+ return EXPP_ReturnPyObjError (PyExc_RuntimeError,
+ "scene to render in bg mode must be the active scene");
+
+ G.scene->r.efra = G.scene->r.sfra;
+
+ RE_animrender(NULL);
+
+ G.scene->r.efra = end_frame;
+ }
+
return EXPP_incr_ret( Py_None );
}
@@ -873,10 +893,22 @@ PyObject *RenderData_RenderAnim( BPy_RenderData * self )
{
Scene *oldsce;
- oldsce = G.scene;
- set_scene( self->scene );
- BIF_do_render( 1 );
- set_scene( oldsce );
+ if (!G.background) {
+ oldsce = G.scene;
+ set_scene( self->scene );
+ BIF_do_render( 1 );
+ set_scene( oldsce );
+ }
+ else { /* background mode (blender -b file.blend -P script) */
+ if (G.scene != self->scene)
+ return EXPP_ReturnPyObjError (PyExc_RuntimeError,
+ "scene to render in bg mode must be the active scene");
+
+ if (G.scene->r.sfra > G.scene->r.efra)
+ return EXPP_ReturnPyObjError (PyExc_RuntimeError,
+ "start frame must be less or equal to end frame");
+ RE_animrender(NULL);
+ }
return EXPP_incr_ret( Py_None );
}
@@ -950,7 +982,7 @@ PyObject *RenderData_SetRenderPath( BPy_RenderData * self, PyObject * args )
"path is too long (SetRenderPath)" ) );
strcpy( self->renderContext->pic, name );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -976,7 +1008,7 @@ PyObject *RenderData_SetBackbufPath( BPy_RenderData * self, PyObject * args )
"path is too long (SetBackbufPath)" ) );
strcpy( self->renderContext->backbuf, name );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
ima = add_image( name );
if( ima ) {
@@ -1014,7 +1046,7 @@ PyObject *RenderData_SetFtypePath( BPy_RenderData * self, PyObject * args )
"path is too long (SetFtypePath)" ) );
strcpy( self->renderContext->ftype, name );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1132,7 +1164,7 @@ PyObject *RenderData_SetOversamplingLevel( BPy_RenderData * self,
"expected 5,8,11, or 16" ) );
self->renderContext->osa = level;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1172,7 +1204,7 @@ PyObject *RenderData_PartsY( BPy_RenderData * self, PyObject * args )
PyObject *RenderData_EnableSky( BPy_RenderData * self )
{
self->renderContext->alphamode = R_ADDSKY;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1181,7 +1213,7 @@ PyObject *RenderData_EnableSky( BPy_RenderData * self )
PyObject *RenderData_EnablePremultiply( BPy_RenderData * self )
{
self->renderContext->alphamode = R_ALPHAPREMUL;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1190,7 +1222,7 @@ PyObject *RenderData_EnablePremultiply( BPy_RenderData * self )
PyObject *RenderData_EnableKey( BPy_RenderData * self )
{
self->renderContext->alphamode = R_ALPHAKEY;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1246,7 +1278,7 @@ PyObject *RenderData_SetRenderWinSize( BPy_RenderData * self, PyObject * args )
"expected 25, 50, 75, or 100" ) );
self->renderContext->size = size;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1328,7 +1360,7 @@ PyObject *RenderData_SetBorder( BPy_RenderData * self, PyObject * args )
self->renderContext->border.xmax = xmax;
self->renderContext->border.ymax = ymax;
- allqueue( REDRAWVIEWCAM, 1 );
+ EXPP_allqueue( REDRAWVIEWCAM, 1 );
return EXPP_incr_ret( Py_None );
}
@@ -1415,7 +1447,7 @@ PyObject *RenderData_SetRenderer( BPy_RenderData * self, PyObject * args )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"expected INTERN or YAFRAY" ) );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1467,7 +1499,7 @@ PyObject *RenderData_SetImageType( BPy_RenderData * self, PyObject * args )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"unknown constant - see modules dict for help" ) );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1491,7 +1523,7 @@ PyObject *RenderData_FramesPerSec( BPy_RenderData * self, PyObject * args )
PyObject *RenderData_EnableGrayscale( BPy_RenderData * self )
{
self->renderContext->planes = R_PLANESBW;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1500,7 +1532,7 @@ PyObject *RenderData_EnableGrayscale( BPy_RenderData * self )
PyObject *RenderData_EnableRGBColor( BPy_RenderData * self )
{
self->renderContext->planes = R_PLANES24;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1509,7 +1541,7 @@ PyObject *RenderData_EnableRGBColor( BPy_RenderData * self )
PyObject *RenderData_EnableRGBAColor( BPy_RenderData * self )
{
self->renderContext->planes = R_PLANES32;
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1583,7 +1615,7 @@ PyObject *RenderData_SizePreset( BPy_RenderData * self, PyObject * args )
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"unknown constant - see modules dict for help" ) );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1613,7 +1645,7 @@ PyObject *RenderData_SetYafrayGIQuality( BPy_RenderData * self,
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"unknown constant - see modules dict for help" ) );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
@@ -1633,7 +1665,7 @@ PyObject *RenderData_SetYafrayGIMethod( BPy_RenderData * self,
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
"unknown constant - see modules dict for help" ) );
- allqueue( REDRAWBUTSSCENE, 0 );
+ EXPP_allqueue( REDRAWBUTSSCENE, 0 );
return EXPP_incr_ret( Py_None );
}
diff --git a/source/blender/src/drawtext.c b/source/blender/src/drawtext.c
index 2acd68a66f3..94bc4801ede 100644
--- a/source/blender/src/drawtext.c
+++ b/source/blender/src/drawtext.c
@@ -966,7 +966,7 @@ void run_python_script(SpaceText *st)
char *py_filename;
Text *text=st->text;
- if (!BPY_txt_do_python(st)) {
+ if (!BPY_txt_do_python_Text(text)) {
int lineno = BPY_Err_getLinenumber();
// jump to error if happened in current text:
py_filename = (char*) BPY_Err_getFilename();
diff --git a/source/blender/src/header_script.c b/source/blender/src/header_script.c
index 27755aafd21..56e76cc9d58 100644
--- a/source/blender/src/header_script.c
+++ b/source/blender/src/header_script.c
@@ -90,7 +90,8 @@ static uiBlock *script_scripts_submenus(void *int_menutype)
BPyMenu *pym;
int i = 0, menutype = (int)int_menutype;
- if ((menutype < 0) || (menutype > PYMENU_TOTAL)) return NULL;
+ if ((menutype < 0) || (menutype > PYMENU_SCRIPTS_MENU_TOTAL))
+ return NULL;
block= uiNewBlock(&curarea->uiblocks, "scriptsscriptssubmenus", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
uiBlockSetButmFunc(block, do_scripts_submenus, int_menutype);
@@ -130,8 +131,6 @@ static void do_script_scriptsmenu(void *arg, int event)
/* Scripts menu */
static uiBlock *script_scriptsmenu(void *arg_unused)
{
- //SpaceScript *sc= curarea->spacedata.first;
- //Script *script= sc->script;
uiBlock *block;
short yco = 0, menuwidth = 120;
int i;
@@ -139,11 +138,11 @@ static uiBlock *script_scriptsmenu(void *arg_unused)
block= uiNewBlock(&curarea->uiblocks, "script_scriptsmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
uiBlockSetButmFunc(block, do_script_scriptsmenu, NULL);
- for (i = 0; i < PYMENU_TOTAL; i++) {
+ for (i = 0; i < PYMENU_SCRIPTS_MENU_TOTAL; i++) {
uiDefIconTextBlockBut(block, script_scripts_submenus, (void *)i, ICON_RIGHTARROW_THIN, BPyMenu_group_itoa(i), 0, yco-=20, menuwidth, 19, "");
}
- uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Update Menus", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "Use when you modify the scripts dir or its contents");
+ uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Update Menus", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 0, "Use when a scripts folder or its contents are modified");
if(curarea->headertype==HEADERTOP) {
uiBlockSetDirection(block, UI_DOWN);
diff --git a/source/blender/src/header_view3d.c b/source/blender/src/header_view3d.c
index b9f15575b24..9a39b95254f 100644
--- a/source/blender/src/header_view3d.c
+++ b/source/blender/src/header_view3d.c
@@ -1030,7 +1030,10 @@ static uiBlock *view3d_select_pose_armaturemenu(void *arg_unused)
static void do_view3d_select_faceselmenu(void *arg, int event)
{
// extern void borderselect(void);
-
+
+ /* events >= 5 are registered bpython scripts */
+ if (event >= 5) BPY_menu_do_python(PYMENU_FACESELECT, event - 5);
+
switch(event) {
case 0: /* border select */
borderselect();
@@ -1052,7 +1055,9 @@ static uiBlock *view3d_select_faceselmenu(void *arg_unused)
{
uiBlock *block;
short yco= 0, menuwidth=120;
-
+ BPyMenu *pym;
+ int i = 0;
+
block= uiNewBlock(&curarea->uiblocks, "view3d_select_faceselmenu", UI_EMBOSSP, UI_HELV, curarea->headwin);
uiBlockSetButmFunc(block, do_view3d_select_faceselmenu, NULL);
@@ -1064,6 +1069,15 @@ static uiBlock *view3d_select_faceselmenu(void *arg_unused)
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Inverse", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Same UV", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 4, "");
+ uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
+
+ /* note that we account for the 5 previous entries with i+5: */
+ for (pym = BPyMenuTable[PYMENU_FACESELECT]; pym; pym = pym->next, i++) {
+ uiDefIconTextBut(block, BUTM, 1, ICON_PYTHON, pym->name, 0, yco-=20,
+ menuwidth, 19, NULL, 0.0, 0.0, 1, i+5,
+ pym->tooltip?pym->tooltip:pym->filename);
+ }
+
if(curarea->headertype==HEADERTOP) {
uiBlockSetDirection(block, UI_DOWN);
}
@@ -3249,6 +3263,7 @@ static uiBlock *view3d_facesel_showhidemenu(void *arg_unused)
uiTextBoundsBlock(block, 60);
return block;
}
+
static void do_view3d_faceselmenu(void *arg, int event)
{
/* code copied from buttons.c :(