2003-02-26 19:22:24 +00:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version. The Blender
|
|
|
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
|
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
|
|
|
* about this.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* This is a new part of Blender.
|
|
|
|
|
*
|
2004-02-29 13:20:34 +00:00
|
|
|
* Contributor(s): Michel Selten, Willian P. Germano, Joseph Gilbert
|
2003-02-26 19:22:24 +00:00
|
|
|
*
|
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
BPython:
- tentative fix for scripts with CR/LF endings and split lines:
in 2.32, the ac3d and vrml2 exporters, for example, had lines
split with '\\\\' and so gave syntax errors when executed on Win
platforms, because the scripts bundled with Win binaries had dos
line endings.
- Chris Keith has written code to execute Python scripts from the
command-line, with '-P ' switch: "blender -P filename":
a Blender.Quit function was also added, so Blender can quit after
running the script (end the script with Blender.Quit()), but there's
still work to be done in this part, including adding more functions,
to load / save .blend files and to run scripts. More testing and
discussions are necessary.
Thanks Chris, for both your contributions and your patience, since I
wasn't available to check / commit this for a while.
2004-03-31 04:18:39 +00:00
|
|
|
//#include "BKE_utildefines.h"
|
|
|
|
|
#include "BIF_usiblender.h"
|
|
|
|
|
|
2003-04-21 20:33:06 +00:00
|
|
|
#include "Blender.h"
|
2003-03-08 18:10:20 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2003-04-21 20:33:06 +00:00
|
|
|
/* Global variables */
|
2003-03-08 18:10:20 +00:00
|
|
|
/*****************************************************************************/
|
2003-04-21 20:33:06 +00:00
|
|
|
PyObject *g_blenderdict;
|
2003-03-08 18:10:20 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: Blender_Set */
|
|
|
|
|
/* Python equivalent: Blender.Set */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
PyObject *Blender_Set (PyObject *self, PyObject *args)
|
2003-02-26 19:22:24 +00:00
|
|
|
{
|
2003-06-28 07:38:21 +00:00
|
|
|
char * name;
|
|
|
|
|
PyObject * arg;
|
|
|
|
|
int framenum;
|
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "sO", &name, &arg))
|
|
|
|
|
{
|
|
|
|
|
/* TODO: Do we need to generate a nice error message here? */
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StringEqual (name, "curframe"))
|
|
|
|
|
{
|
|
|
|
|
if (!PyArg_Parse(arg, "i", &framenum))
|
|
|
|
|
{
|
|
|
|
|
/* TODO: Do we need to generate a nice error message here? */
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
G.scene->r.cfra = framenum;
|
|
|
|
|
|
|
|
|
|
update_for_newframe();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return (PythonReturnErrorObject (PyExc_AttributeError,
|
|
|
|
|
"bad request identifier"));
|
|
|
|
|
}
|
|
|
|
|
return ( PythonIncRef (Py_None) );
|
2003-02-26 19:22:24 +00:00
|
|
|
}
|
2003-03-08 18:10:20 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: Blender_Get */
|
|
|
|
|
/* Python equivalent: Blender.Get */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
PyObject *Blender_Get (PyObject *self, PyObject *args)
|
|
|
|
|
{
|
2003-06-28 07:38:21 +00:00
|
|
|
PyObject * object;
|
|
|
|
|
PyObject * dict;
|
|
|
|
|
char * str;
|
2003-05-28 04:36:18 +00:00
|
|
|
|
2003-06-28 07:38:21 +00:00
|
|
|
if (!PyArg_ParseTuple (args, "O", &object))
|
|
|
|
|
{
|
|
|
|
|
/* TODO: Do we need to generate a nice error message here? */
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) );
|
|
|
|
|
}
|
|
|
|
|
/* 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",
|
2004-01-13 14:50:45 +00:00
|
|
|
PyInt_FromLong (U.vrmlflag & USER_VRML_TWOSIDED));
|
2003-06-28 07:38:21 +00:00
|
|
|
|
|
|
|
|
PyDict_SetItemString (dict, "layers",
|
2004-01-13 14:50:45 +00:00
|
|
|
PyInt_FromLong (U.vrmlflag & USER_VRML_LAYERS));
|
2003-06-28 07:38:21 +00:00
|
|
|
|
|
|
|
|
PyDict_SetItemString (dict, "autoscale",
|
2004-01-13 14:50:45 +00:00
|
|
|
PyInt_FromLong (U.vrmlflag & USER_VRML_AUTOSCALE));
|
2003-06-28 07:38:21 +00:00
|
|
|
|
|
|
|
|
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 (PythonReturnErrorObject (..., "message") );
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return (PythonReturnErrorObject (PyExc_AttributeError,
|
|
|
|
|
"expected string argument"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (PythonReturnErrorObject (PyExc_AttributeError,
|
2003-05-28 04:36:18 +00:00
|
|
|
"bad request identifier"));
|
2003-03-08 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: Blender_Redraw */
|
|
|
|
|
/* Python equivalent: Blender.Redraw */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
PyObject *Blender_Redraw(PyObject *self, PyObject *args)
|
|
|
|
|
{
|
2003-06-28 07:38:21 +00:00
|
|
|
int wintype = SPACE_VIEW3D;
|
2003-03-08 18:10:20 +00:00
|
|
|
|
2003-06-28 07:38:21 +00:00
|
|
|
if (!PyArg_ParseTuple (args, "|i", &wintype))
|
|
|
|
|
{
|
|
|
|
|
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
2003-05-28 04:36:18 +00:00
|
|
|
"expected int argument (or nothing)");
|
2003-06-28 07:38:21 +00:00
|
|
|
}
|
2003-03-08 18:10:20 +00:00
|
|
|
|
2003-06-28 07:38:21 +00:00
|
|
|
return M_Window_Redraw(self, Py_BuildValue("(i)", wintype));
|
2003-03-08 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-13 01:54:28 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: Blender_ReleaseGlobalDict */
|
|
|
|
|
/* Python equivalent: Blender.ReleaseGlobalDict */
|
BPython:
- tentative fix for scripts with CR/LF endings and split lines:
in 2.32, the ac3d and vrml2 exporters, for example, had lines
split with '\\\\' and so gave syntax errors when executed on Win
platforms, because the scripts bundled with Win binaries had dos
line endings.
- Chris Keith has written code to execute Python scripts from the
command-line, with '-P ' switch: "blender -P filename":
a Blender.Quit function was also added, so Blender can quit after
running the script (end the script with Blender.Quit()), but there's
still work to be done in this part, including adding more functions,
to load / save .blend files and to run scripts. More testing and
discussions are necessary.
Thanks Chris, for both your contributions and your patience, since I
wasn't available to check / commit this for a while.
2004-03-31 04:18:39 +00:00
|
|
|
/* Description: Deprecated function. */
|
2003-05-13 01:54:28 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
PyObject *Blender_ReleaseGlobalDict(PyObject *self, PyObject *args)
|
|
|
|
|
{
|
BPython:
- tentative fix for scripts with CR/LF endings and split lines:
in 2.32, the ac3d and vrml2 exporters, for example, had lines
split with '\\\\' and so gave syntax errors when executed on Win
platforms, because the scripts bundled with Win binaries had dos
line endings.
- Chris Keith has written code to execute Python scripts from the
command-line, with '-P ' switch: "blender -P filename":
a Blender.Quit function was also added, so Blender can quit after
running the script (end the script with Blender.Quit()), but there's
still work to be done in this part, including adding more functions,
to load / save .blend files and to run scripts. More testing and
discussions are necessary.
Thanks Chris, for both your contributions and your patience, since I
wasn't available to check / commit this for a while.
2004-03-31 04:18:39 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: Blender_Quit */
|
|
|
|
|
/* Python equivalent: Blender.Quit */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
PyObject *Blender_Quit(PyObject *self)
|
|
|
|
|
{
|
|
|
|
|
exit_usiblender();
|
2003-05-13 01:54:28 +00:00
|
|
|
|
BPython:
- tentative fix for scripts with CR/LF endings and split lines:
in 2.32, the ac3d and vrml2 exporters, for example, had lines
split with '\\\\' and so gave syntax errors when executed on Win
platforms, because the scripts bundled with Win binaries had dos
line endings.
- Chris Keith has written code to execute Python scripts from the
command-line, with '-P ' switch: "blender -P filename":
a Blender.Quit function was also added, so Blender can quit after
running the script (end the script with Blender.Quit()), but there's
still work to be done in this part, including adding more functions,
to load / save .blend files and to run scripts. More testing and
discussions are necessary.
Thanks Chris, for both your contributions and your patience, since I
wasn't available to check / commit this for a while.
2004-03-31 04:18:39 +00:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
|
return Py_None;
|
2003-05-13 01:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-08 18:10:20 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Function: initBlender */
|
|
|
|
|
/*****************************************************************************/
|
2003-05-17 13:46:15 +00:00
|
|
|
void M_Blender_Init (void)
|
2003-03-08 18:10:20 +00:00
|
|
|
{
|
2003-06-28 07:38:21 +00:00
|
|
|
PyObject * module;
|
|
|
|
|
PyObject * dict;
|
|
|
|
|
|
|
|
|
|
g_blenderdict = NULL;
|
|
|
|
|
|
|
|
|
|
/* TODO: create a docstring for the Blender module */
|
|
|
|
|
module = Py_InitModule3("Blender", Blender_methods, NULL);
|
|
|
|
|
|
2004-04-23 13:11:48 +00:00
|
|
|
types_InitAll(); /* set all our pytypes to &PyType_Type*/
|
|
|
|
|
|
2003-06-28 07:38:21 +00:00
|
|
|
dict = PyModule_GetDict (module);
|
|
|
|
|
g_blenderdict = dict;
|
2004-04-23 13:11:48 +00:00
|
|
|
PyDict_SetItemString (dict, "Types", Types_Init());
|
2003-06-28 07:38:21 +00:00
|
|
|
PyDict_SetItemString (dict, "sys", sys_Init());
|
2003-09-03 04:13:08 +00:00
|
|
|
PyDict_SetItemString (dict, "Registry", Registry_Init());
|
2003-06-28 07:38:21 +00:00
|
|
|
PyDict_SetItemString (dict, "Scene", Scene_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Object", Object_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Material", Material_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Camera", Camera_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Lamp", Lamp_Init());
|
2003-11-13 04:00:59 +00:00
|
|
|
PyDict_SetItemString (dict, "Lattice", Lattice_Init());
|
2003-06-28 07:38:21 +00:00
|
|
|
PyDict_SetItemString (dict, "Curve", Curve_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Armature", Armature_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Ipo", Ipo_Init());
|
2004-02-29 13:20:34 +00:00
|
|
|
PyDict_SetItemString (dict, "IpoCurve", IpoCurve_Init());
|
2003-06-28 07:38:21 +00:00
|
|
|
PyDict_SetItemString (dict, "Metaball", Metaball_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Image", Image_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Window", Window_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Draw", Draw_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "BGL", BGL_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Effect", Effect_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Text", Text_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "World", World_Init());
|
2003-11-23 17:46:06 +00:00
|
|
|
PyDict_SetItemString (dict, "Texture", Texture_Init());
|
2004-04-23 13:11:48 +00:00
|
|
|
PyDict_SetItemString (dict, "NMesh", NMesh_Init());
|
2004-04-03 13:59:27 +00:00
|
|
|
PyDict_SetItemString (dict, "Noise", Noise_Init());
|
2004-04-21 14:24:59 +00:00
|
|
|
PyDict_SetItemString (dict, "Mathutils",Mathutils_Init());
|
2003-03-08 18:10:20 +00:00
|
|
|
}
|