1135
1135
return (PyObject *)lib;
1138
static PyObject *M_Library_GetPaths(PyObject *self, PyObject * args)
1145
if( !PyArg_ParseTuple( args, "|i", &type ) || type < 0 || type > 2 ) {
1146
return EXPP_ReturnPyObjError( PyExc_TypeError,
1147
"expected an int between 0 and 2." );
1150
list = PyList_New(0);
1152
for(lib= G.main->library.first; lib; lib= lib->id.next) {
1154
/* any type is ok */
1155
} else if (type==1 && lib->parent == 0) {
1156
/* only direct linked */
1157
} else if (type==2 && lib->parent != 0) {
1160
continue; /* incompatible type */
1163
name = PyString_FromString(lib->name);
1164
PyList_Append(list, name);
1170
static PyObject *M_Library_ReplacePath(PyObject *self, PyObject * args)
1172
char *name_from, *name_to;
1175
if( !PyArg_ParseTuple( args, "ss", &name_from, &name_to )) {
1176
return EXPP_ReturnPyObjError( PyExc_TypeError,
1177
"expected the name of a library path" );
1180
for(lib= G.main->library.first; lib; lib= lib->id.next) {
1181
if (strcmp(lib->name, name_from)==0) {
1183
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1184
"path is indirectly linked, cannot be changed." );
1187
if (strlen(name_to) > sizeof(lib->name)) {
1188
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1189
"string length too long, cannot set path." );
1192
strcpy(lib->name, name_to);
1197
return EXPP_ReturnPyObjError( PyExc_ValueError,
1198
"path given does not exist as a library" );
1138
1203
static struct PyMethodDef M_Library_methods[] = {
1139
1204
{"load", (PyCFunction)M_Library_Load, METH_VARARGS,
1140
1205
"(string) - declare a .blend file for use as a library"},
1206
{"paths", (PyCFunction)M_Library_GetPaths, METH_VARARGS,
1207
"(type) - return a list of library paths, type 0 for all, 1 only direct links, 2 only indirect links"},
1208
{"replace", (PyCFunction)M_Library_ReplacePath, METH_VARARGS,
1209
"(from, to) - replace the path of an existing, directly linked library."},
1141
1210
{NULL, NULL, 0, NULL}