Added functions so python can change library paths.
* bpy.libraries.paths() -> list of library paths. * bpy.libraries.replace(fromPath, toPath)
This commit is contained in:
@@ -1135,9 +1135,78 @@ static PyObject *M_Library_Load(PyObject *self, PyObject * args)
|
|||||||
return (PyObject *)lib;
|
return (PyObject *)lib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject *M_Library_GetPaths(PyObject *self, PyObject * args)
|
||||||
|
{
|
||||||
|
PyObject *list;
|
||||||
|
PyObject *name;
|
||||||
|
int type=0;
|
||||||
|
Library *lib;
|
||||||
|
|
||||||
|
if( !PyArg_ParseTuple( args, "|i", &type ) || type < 0 || type > 2 ) {
|
||||||
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||||
|
"expected an int between 0 and 2." );
|
||||||
|
}
|
||||||
|
|
||||||
|
list = PyList_New(0);
|
||||||
|
|
||||||
|
for(lib= G.main->library.first; lib; lib= lib->id.next) {
|
||||||
|
if (type==0) {
|
||||||
|
/* any type is ok */
|
||||||
|
} else if (type==1 && lib->parent == 0) {
|
||||||
|
/* only direct linked */
|
||||||
|
} else if (type==2 && lib->parent != 0) {
|
||||||
|
/* only indirect */
|
||||||
|
} else {
|
||||||
|
continue; /* incompatible type */
|
||||||
|
}
|
||||||
|
|
||||||
|
name = PyString_FromString(lib->name);
|
||||||
|
PyList_Append(list, name);
|
||||||
|
Py_DECREF(name);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *M_Library_ReplacePath(PyObject *self, PyObject * args)
|
||||||
|
{
|
||||||
|
char *name_from, *name_to;
|
||||||
|
Library *lib;
|
||||||
|
|
||||||
|
if( !PyArg_ParseTuple( args, "ss", &name_from, &name_to )) {
|
||||||
|
return EXPP_ReturnPyObjError( PyExc_TypeError,
|
||||||
|
"expected the name of a library path" );
|
||||||
|
}
|
||||||
|
|
||||||
|
for(lib= G.main->library.first; lib; lib= lib->id.next) {
|
||||||
|
if (strcmp(lib->name, name_from)==0) {
|
||||||
|
if (lib->parent) {
|
||||||
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||||
|
"path is indirectly linked, cannot be changed." );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(name_to) > sizeof(lib->name)) {
|
||||||
|
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
|
||||||
|
"string length too long, cannot set path." );
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(lib->name, name_to);
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXPP_ReturnPyObjError( PyExc_ValueError,
|
||||||
|
"path given does not exist as a library" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static struct PyMethodDef M_Library_methods[] = {
|
static struct PyMethodDef M_Library_methods[] = {
|
||||||
{"load", (PyCFunction)M_Library_Load, METH_VARARGS,
|
{"load", (PyCFunction)M_Library_Load, METH_VARARGS,
|
||||||
"(string) - declare a .blend file for use as a library"},
|
"(string) - declare a .blend file for use as a library"},
|
||||||
|
{"paths", (PyCFunction)M_Library_GetPaths, METH_VARARGS,
|
||||||
|
"(type) - return a list of library paths, type 0 for all, 1 only direct links, 2 only indirect links"},
|
||||||
|
{"replace", (PyCFunction)M_Library_ReplacePath, METH_VARARGS,
|
||||||
|
"(from, to) - replace the path of an existing, directly linked library."},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -27,17 +27,37 @@ Example::
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def load(filename,relative=False):
|
def load(filename,relative=False):
|
||||||
"""
|
"""
|
||||||
Select an existing .blend file for use as a library. Unlike the
|
Select an existing .blend file for use as a library. Unlike the
|
||||||
Library module, multiple libraries can be defined at the same time.
|
Library module, multiple libraries can be defined at the same time.
|
||||||
|
|
||||||
@type filename: string
|
@type filename: string
|
||||||
@param filename: The filename of a Blender file. Filenames starting with "//" will be loaded relative to the blend file's location.
|
@param filename: The filename of a Blender file. Filenames starting with "//" will be loaded relative to the blend file's location.
|
||||||
@type relative: boolean
|
@type relative: boolean
|
||||||
@param relative: Convert relative paths to absolute paths (default). Setting this parameter to True will leave paths relative.
|
@param relative: Convert relative paths to absolute paths (default). Setting this parameter to True will leave paths relative.
|
||||||
@rtype: Library
|
@rtype: Library
|
||||||
@return: return a L{Library} object.
|
@return: return a L{Library} object.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def paths(link=0):
|
||||||
|
"""
|
||||||
|
Returns a list of paths used in the current blend file.
|
||||||
|
|
||||||
|
@type link: int
|
||||||
|
@param link: 0 (default if no args given) for all library paths, 1 for directly linked library paths only, 2 for indirectly linked library paths only.
|
||||||
|
@rtype: List
|
||||||
|
@return: return a list of path strings.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def replace(pathFrom, pathTo):
|
||||||
|
"""
|
||||||
|
Replaces an existing directly linked path.
|
||||||
|
|
||||||
|
@type pathFrom: string
|
||||||
|
@param pathFrom: An existing library path.
|
||||||
|
@type pathTo: string
|
||||||
|
@param pathTo: A new library path.
|
||||||
|
"""
|
||||||
|
|
||||||
class Libraries:
|
class Libraries:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user