Added Image.GetCurrent()
Previously the only way to get the current image was flaky and relyd on the image being assigned to a mesh. try: me = Scene.GetCurrent().getAttiveObject().getData(mesh=1) image = me.faces[me.activeFace].image except: image = None ...Can new be replaced by the following, and works even when there is no mesh. image = Image.GetCurrent() epydocs: Get the currently displayed Image from Blenders UV/Image window. When multiple images are displayed, the last active UV/Image windows image is used.
This commit is contained in:
@@ -69,6 +69,7 @@ short IMB_saveiff( struct ImBuf *ibuf, char *naam, int flags );
|
|||||||
/*static PyObject *M_Image_New( PyObject * self, PyObject * args,
|
/*static PyObject *M_Image_New( PyObject * self, PyObject * args,
|
||||||
PyObject * keywords );*/
|
PyObject * keywords );*/
|
||||||
static PyObject *M_Image_Get( PyObject * self, PyObject * args );
|
static PyObject *M_Image_Get( PyObject * self, PyObject * args );
|
||||||
|
static PyObject *M_Image_GetCurrent( PyObject * self );
|
||||||
static PyObject *M_Image_Load( PyObject * self, PyObject * args );
|
static PyObject *M_Image_Load( PyObject * self, PyObject * args );
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -86,6 +87,10 @@ static char M_Image_Get_doc[] =
|
|||||||
returns None if not found.\n If 'name' is not specified, \
|
returns None if not found.\n If 'name' is not specified, \
|
||||||
it returns a list of all images in the\ncurrent scene.";
|
it returns a list of all images in the\ncurrent scene.";
|
||||||
|
|
||||||
|
static char M_Image_GetCurrent_doc[] =
|
||||||
|
"() - return the current image, from last active the uv/image view, \
|
||||||
|
returns None no image is in the view.\n";
|
||||||
|
|
||||||
static char M_Image_Load_doc[] =
|
static char M_Image_Load_doc[] =
|
||||||
"(filename) - return image from file filename as Image Object, \
|
"(filename) - return image from file filename as Image Object, \
|
||||||
returns None if not found.\n";
|
returns None if not found.\n";
|
||||||
@@ -97,6 +102,7 @@ struct PyMethodDef M_Image_methods[] = {
|
|||||||
/*{"New", ( PyCFunction ) M_Image_New, METH_VARARGS | METH_KEYWORDS,
|
/*{"New", ( PyCFunction ) M_Image_New, METH_VARARGS | METH_KEYWORDS,
|
||||||
M_Image_New_doc}, */
|
M_Image_New_doc}, */
|
||||||
{"Get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
|
{"Get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
|
||||||
|
{"GetCurrent", M_Image_GetCurrent, METH_NOARGS, M_Image_GetCurrent_doc},
|
||||||
{"get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
|
{"get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
|
||||||
{"Load", M_Image_Load, METH_VARARGS, M_Image_Load_doc},
|
{"Load", M_Image_Load, METH_VARARGS, M_Image_Load_doc},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
@@ -170,11 +176,6 @@ static PyObject *M_Image_Get( PyObject * self, PyObject * args )
|
|||||||
while( img_iter ) {
|
while( img_iter ) {
|
||||||
pyobj = Image_CreatePyObject( img_iter );
|
pyobj = Image_CreatePyObject( img_iter );
|
||||||
|
|
||||||
if( !pyobj )
|
|
||||||
return ( EXPP_ReturnPyObjError
|
|
||||||
( PyExc_MemoryError,
|
|
||||||
"couldn't create PyObject" ) );
|
|
||||||
|
|
||||||
PyList_SET_ITEM( img_list, index, pyobj );
|
PyList_SET_ITEM( img_list, index, pyobj );
|
||||||
|
|
||||||
img_iter = img_iter->id.next;
|
img_iter = img_iter->id.next;
|
||||||
@@ -185,6 +186,26 @@ static PyObject *M_Image_Get( PyObject * self, PyObject * args )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Function: M_Image_GetCurrent */
|
||||||
|
/* Python equivalent: Blender.Image.GetCurrent */
|
||||||
|
/* Description: Returns the active current (G.sima) */
|
||||||
|
/* This will be the image last under the mouse cursor */
|
||||||
|
/* None if there is no Image. */
|
||||||
|
/*****************************************************************************/
|
||||||
|
static PyObject *M_Image_GetCurrent( PyObject * self )
|
||||||
|
{
|
||||||
|
PyObject *current_img;
|
||||||
|
if (!G.sima || !G.sima->image) Py_RETURN_NONE;
|
||||||
|
current_img = Image_CreatePyObject( G.sima->image );
|
||||||
|
return current_img;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Function: M_Image_Load */
|
/* Function: M_Image_Load */
|
||||||
/* Python equivalent: Blender.Image.Load */
|
/* Python equivalent: Blender.Image.Load */
|
||||||
@@ -674,15 +695,13 @@ static void Image_dealloc( BPy_Image * self )
|
|||||||
PyObject *Image_CreatePyObject( Image * image )
|
PyObject *Image_CreatePyObject( Image * image )
|
||||||
{
|
{
|
||||||
BPy_Image *py_img;
|
BPy_Image *py_img;
|
||||||
|
|
||||||
py_img = ( BPy_Image * ) PyObject_NEW( BPy_Image, &Image_Type );
|
py_img = ( BPy_Image * ) PyObject_NEW( BPy_Image, &Image_Type );
|
||||||
|
|
||||||
if( !py_img )
|
if( !py_img )
|
||||||
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
return EXPP_ReturnPyObjError( PyExc_MemoryError,
|
||||||
"couldn't create BPy_Image object" );
|
"couldn't create BPy_Image object" );
|
||||||
|
|
||||||
py_img->image = image;
|
py_img->image = image;
|
||||||
|
|
||||||
return ( PyObject * ) py_img;
|
return ( PyObject * ) py_img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,13 @@ def Get (name = None):
|
|||||||
- (): A list with all Image objects in the current scene.
|
- (): A list with all Image objects in the current scene.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def GetCurrent ():
|
||||||
|
"""
|
||||||
|
Get the currently displayed Image from Blenders UV/Image window.
|
||||||
|
When multiple images are displayed, the last active UV/Image windows image is used.
|
||||||
|
@rtype: Blender Image
|
||||||
|
@return: The Current Blender Image, If there is no current image it returns None.
|
||||||
|
"""
|
||||||
|
|
||||||
class Image:
|
class Image:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user