diff options
Diffstat (limited to 'source/blender/python/api2_2x')
-rw-r--r-- | source/blender/python/api2_2x/Effect.c | 70 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Object.c | 4 | ||||
-rw-r--r-- | source/blender/python/api2_2x/Window.c | 2 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/API_intro.py | 30 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Effect.py | 13 |
5 files changed, 83 insertions, 36 deletions
diff --git a/source/blender/python/api2_2x/Effect.c b/source/blender/python/api2_2x/Effect.c index 388f93db0b9..2e3e65e2c77 100644 --- a/source/blender/python/api2_2x/Effect.c +++ b/source/blender/python/api2_2x/Effect.c @@ -133,41 +133,74 @@ PyObject *M_Effect_Get( PyObject * self, PyObject * args ) { /*arguments : string object name int : position of effect in the obj's effect list */ - char *name = 0; + char *name = NULL; Object *object_iter; Effect *eff; BPy_Effect *wanted_eff; - int num, i; + int num = -1, i; + if( !PyArg_ParseTuple( args, "|si", &name, &num ) ) return ( EXPP_ReturnPyObjError( PyExc_AttributeError, "expected string int argument" ) ); + object_iter = G.main->object.first; + if( !object_iter ) return ( EXPP_ReturnPyObjError( PyExc_AttributeError, "Scene contains no object" ) ); - if( name ) { + + if( name ) { /* (name, num = -1) - try to find the given object */ + while( object_iter ) { - if( strcmp( name, object_iter->id.name + 2 ) ) { - object_iter = object_iter->id.next; - continue; - } + if( !strcmp( name, object_iter->id.name + 2 ) ) { - if( object_iter->effect.first != NULL ) { - eff = object_iter->effect.first; - for( i = 0; i < num; i++ ) - eff = eff->next; - wanted_eff = - ( BPy_Effect * ) - PyObject_NEW( BPy_Effect, - &Effect_Type ); - wanted_eff->effect = eff; - return ( PyObject * ) wanted_eff; + eff = object_iter->effect.first; /*can be NULL: None will be returned*/ + + if (num >= 0) { /* return effect in given num position if available */ + + for( i = 0; i < num; i++ ) { + if (!eff) break; + eff = eff->next; + } + + if (eff) { + wanted_eff = (BPy_Effect *)PyObject_NEW(BPy_Effect, &Effect_Type); + wanted_eff->effect = eff; + return ( PyObject * ) wanted_eff; + } else { /* didn't find any effect in the given position */ + Py_INCREF(Py_None); + return Py_None; + } + } + + else {/*return a list with all effects linked to the given object*/ + /* this was pointed by Stephen Swaney */ + PyObject *effectlist = PyList_New( 0 ); + + while (eff) { + BPy_Effect *found_eff = (BPy_Effect *)PyObject_NEW(BPy_Effect, + &Effect_Type); + found_eff->effect = eff; + PyList_Append( effectlist, ( PyObject * ) found_eff ); + Py_DECREF((PyObject *)found_eff); /* PyList_Append incref'ed it */ + eff = eff->next; + } + return effectlist; + } } + object_iter = object_iter->id.next; } - } else { + + if (!object_iter) + return EXPP_ReturnPyObjError (PyExc_AttributeError, + "no such object"); + } + + else { /* () - return a list with all effects currently in Blender */ PyObject *effectlist = PyList_New( 0 ); + while( object_iter ) { if( object_iter->effect.first != NULL ) { eff = object_iter->effect.first; @@ -180,6 +213,7 @@ PyObject *M_Effect_Get( PyObject * self, PyObject * args ) PyList_Append( effectlist, ( PyObject * ) found_eff ); + Py_DECREF((PyObject *)found_eff); eff = eff->next; } } diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c index 6311f2be933..e9048ffad3a 100644 --- a/source/blender/python/api2_2x/Object.c +++ b/source/blender/python/api2_2x/Object.c @@ -197,7 +197,7 @@ hierarchy (faster)"}, if i is nonzero, empty slots are not ignored: they are returned as None's."}, {"getMatrix", ( PyCFunction ) Object_getMatrix, METH_VARARGS, "(str = 'worldspace') - Returns the object matrix.\n\ -(str = 'localspace') - the wanted matrix: worldspace (default), localspace\n\ +(str = 'worldspace') - the wanted matrix: worldspace (default), localspace\n\ or old_worldspace.\n\ \n\ 'old_worldspace' was the only behavior before Blender 2.34. With it the\n\ @@ -957,7 +957,7 @@ static PyObject *Object_getMaterials( BPy_Object * self, PyObject * args ) static PyObject *Object_getMatrix( BPy_Object * self, PyObject * args ) { PyObject *matrix; - char *space = "worldspace"; /* default to local */ + char *space = "worldspace"; /* default to world */ if( !PyArg_ParseTuple( args, "|s", &space ) ) { return ( EXPP_ReturnPyObjError( PyExc_AttributeError, diff --git a/source/blender/python/api2_2x/Window.c b/source/blender/python/api2_2x/Window.c index 067bfc8d33a..1053c29e930 100644 --- a/source/blender/python/api2_2x/Window.c +++ b/source/blender/python/api2_2x/Window.c @@ -971,7 +971,7 @@ static PyObject *M_Window_QAdd( PyObject * self, PyObject * args ) static PyObject *M_Window_QHandle( PyObject * self, PyObject * args ) { short win; - ScrArea *sa = curarea; + ScrArea *sa = G.curscreen->areabase.first; ScrArea *oldsa = NULL; if( !PyArg_ParseTuple( args, "h", &win ) ) diff --git a/source/blender/python/api2_2x/doc/API_intro.py b/source/blender/python/api2_2x/doc/API_intro.py index 8f684c79144..bceef653dca 100644 --- a/source/blender/python/api2_2x/doc/API_intro.py +++ b/source/blender/python/api2_2x/doc/API_intro.py @@ -18,7 +18,7 @@ The Blender Python API Reference - L{Camera} - L{Curve} - L{Draw} - - L{Effect} + - L{Effect} (*) - L{Image} - L{Ipo} - L{Lamp} @@ -97,15 +97,16 @@ Registering scripts: The header should be like this one (all double and single apostrophes below are required):: #!BPY - \"\"\" - Name: 'Script Name' - Blender: 233 - Group: 'Export' - Submenu: 'All' all - Submenu: 'Selected' sel - Submenu: 'Configure (gui)' gui - Tooltip: 'Export to some format.' - \"\"\" + + # \"\"\" + # Name: 'Script Name' + # Blender: 233 + # Group: 'Export' + # Submenu: 'All' all + # Submenu: 'Selected' sel + # Submenu: 'Configure (gui)' gui + # Tooltip: 'Export to some format.' + # \"\"\" where: - B{Name} is the string that will appear in the menu; @@ -115,6 +116,15 @@ Registering scripts: - B{Submenu} adds optional submenus for further control; - B{Tooltip} is the (short) tooltip string for the menu entry. + note: + - all double and single apostrophes above are required; + - B{*NEW*}: you can "comment out" the header above, by starting lines with + '#', like we did. This is not required (except for the first line, #!BPY, + of course), but this way the header won't conflict with Python tools that + you can use to generate documentation for your script code. Just + remember to keep this header above any other line with triple + double-quotes (\"\"\") in your script. + Submenu lines are not required, use them if you want to provide extra options. To see which submenu the user chose, check the "__script__" dictionary in your code: __script__['arg'] has the defined keyword (the word diff --git a/source/blender/python/api2_2x/doc/Effect.py b/source/blender/python/api2_2x/doc/Effect.py index e25310cbced..b503523d3ec 100644 --- a/source/blender/python/api2_2x/doc/Effect.py +++ b/source/blender/python/api2_2x/doc/Effect.py @@ -3,6 +3,8 @@ """ The Blender.Effect submodule +B{new}: now L{Get}('objname') (without specifying second paramenter: 'position') returns a list of all effects linked to object "objname". + INTRODUCTION The module effect allows you to access all the data of an effect. @@ -39,16 +41,17 @@ def New (type): @return: The created Effect. """ -def Get (objname,position): +def Get (objname, position = None): """ Get an Effect from Blender. @type objname: string @param objname: The name of object to which is linked the effect. - @type position: string - @param position: The position of the effect in the list of effects liked to the object. + @type position: int + @param position: The position of the effect in the list of effects linked to the object. @rtype: Blender Effect or a list of Blender Effects - @return: It depends on the 'objname,position' parameters: - - (objname,position): The Effect linked to the given object at the given position; + @return: It depends on the 'objname, position' parameters: + - (objname): A list with all Effects linked to the given object (new); + - (objname, position): The Effect linked to the given object at the given position; - (): A list with all Effects in the current scene. """ |