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,
|
2004-04-24 20:04:37 +00:00
|
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2003-02-26 19:22:24 +00:00
|
|
|
*
|
|
|
|
|
* 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 *****
|
|
|
|
|
*/
|
|
|
|
|
|
2004-05-18 03:23:45 +00:00
|
|
|
#include <Python.h>
|
|
|
|
|
#include <stdio.h>
|
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
|
|
|
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
/* for open, close in Blender_Load */
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#ifndef WIN32
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#else
|
|
|
|
|
#include "BLI_winstuff.h"
|
|
|
|
|
#include <io.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-05-18 03:23:45 +00:00
|
|
|
#include <BIF_usiblender.h>
|
|
|
|
|
#include <BLI_blenlib.h>
|
2004-06-24 09:43:13 +00:00
|
|
|
#include <BLO_writefile.h>
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
#include <BKE_exotic.h>
|
2004-05-18 03:23:45 +00:00
|
|
|
#include <BKE_global.h>
|
2004-06-24 09:43:13 +00:00
|
|
|
#include <BKE_packedFile.h>
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
#include <BKE_object.h>
|
2004-05-18 03:23:45 +00:00
|
|
|
#include <BPI_script.h>
|
|
|
|
|
#include <BSE_headerbuttons.h>
|
|
|
|
|
#include <DNA_ID.h>
|
|
|
|
|
#include <DNA_object_types.h>
|
|
|
|
|
#include <DNA_scene_types.h>
|
|
|
|
|
#include <DNA_screen_types.h> /* for SPACE_VIEW3D */
|
2004-05-22 20:25:22 +00:00
|
|
|
#include <DNA_space_types.h> /* for SPACE_VIEW3D */
|
2004-05-18 03:23:45 +00:00
|
|
|
#include <DNA_userdef_types.h>
|
|
|
|
|
#include <BKE_ipo.h>
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
#include <blendef.h>
|
2004-05-18 03:23:45 +00:00
|
|
|
|
|
|
|
|
#include "gen_utils.h"
|
|
|
|
|
#include "modules.h"
|
2004-05-22 20:25:22 +00:00
|
|
|
#include "../BPY_extern.h" /* for bpy_gethome() */
|
2004-05-18 03:23:45 +00:00
|
|
|
|
|
|
|
|
/* From Window.h, used here by Blender_Redraw */
|
|
|
|
|
PyObject *M_Window_Redraw(PyObject *self, PyObject *args);
|
|
|
|
|
|
|
|
|
|
/**********************************************************/
|
|
|
|
|
/* Python API function prototypes for the Blender module. */
|
|
|
|
|
/**********************************************************/
|
|
|
|
|
static PyObject *Blender_Set (PyObject *self, PyObject *args);
|
|
|
|
|
static PyObject *Blender_Get (PyObject *self, PyObject *args);
|
|
|
|
|
static PyObject *Blender_Redraw(PyObject *self, PyObject *args);
|
|
|
|
|
static PyObject *Blender_ReleaseGlobalDict(PyObject *self, PyObject *args);
|
|
|
|
|
static PyObject *Blender_Quit(PyObject *self);
|
|
|
|
|
static PyObject *Blender_Load(PyObject *self, PyObject *args);
|
2004-06-24 09:43:13 +00:00
|
|
|
static PyObject *Blender_Save(PyObject *self, PyObject *args);
|
2004-05-18 03:23:45 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* The following string definitions are used for documentation strings. */
|
|
|
|
|
/* In Python these will be written to the console when doing a */
|
|
|
|
|
/* Blender.__doc__ */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
static char Blender_Set_doc[] =
|
|
|
|
|
"(request, data) - Update settings in Blender\n\
|
|
|
|
|
\n\
|
|
|
|
|
(request) A string identifying the setting to change\n\
|
|
|
|
|
'curframe' - Sets the current frame using the number in data";
|
|
|
|
|
|
|
|
|
|
static char Blender_Get_doc[] =
|
|
|
|
|
"(request) - Retrieve settings from Blender\n\
|
|
|
|
|
\n\
|
|
|
|
|
(request) A string indentifying the data to be returned\n\
|
|
|
|
|
'curframe' - Returns the current animation frame\n\
|
|
|
|
|
'curtime' - Returns the current animation time\n\
|
|
|
|
|
'staframe' - Returns the start frame of the animation\n\
|
|
|
|
|
'endframe' - Returns the end frame of the animation\n\
|
|
|
|
|
'filename' - Returns the name of the last file read or written\n\
|
2004-05-22 20:25:22 +00:00
|
|
|
'datadir' - Returns the dir where scripts can save their data, if available\n\
|
2004-05-18 03:23:45 +00:00
|
|
|
'version' - Returns the Blender version number";
|
|
|
|
|
|
|
|
|
|
static char Blender_Redraw_doc[] = "() - Redraw all 3D windows";
|
|
|
|
|
|
|
|
|
|
static char Blender_ReleaseGlobalDict_doc[] =
|
|
|
|
|
"Deprecated, please use the Blender.Registry module solution instead.";
|
|
|
|
|
|
|
|
|
|
static char Blender_Quit_doc[] =
|
|
|
|
|
"() - Quit Blender. The current data is saved as 'quit.blend' before leaving.";
|
|
|
|
|
|
|
|
|
|
static char Blender_Load_doc[] =
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
"(filename) - Load the given file.\n\
|
|
|
|
|
Supported formats:\n\
|
|
|
|
|
Blender, DXF, Inventor 1.0 ASCII, VRML 1.0 asc, STL, Videoscape, radiogour.\n\
|
|
|
|
|
\n\
|
2004-05-18 03:23:45 +00:00
|
|
|
Notes:\n\
|
|
|
|
|
1 - () - an empty argument loads the default .B.blend file;\n\
|
|
|
|
|
2 - if the substring '.B.blend' occurs inside 'filename', the default\n\
|
|
|
|
|
.B.blend file is loaded;\n\
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
3 - If a Blender file is loaded the script ends immediately.\n\
|
|
|
|
|
4 - The current data is always preserved as an autosave file, for safety;\n\
|
|
|
|
|
5 - This function only works if the script where it's executed is the\n\
|
|
|
|
|
only one running at the moment.";
|
2004-05-18 03:23:45 +00:00
|
|
|
|
2004-06-24 09:43:13 +00:00
|
|
|
static char Blender_Save_doc[] =
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
"(filename) - Save data to a file based on the filename's extension.\n\
|
|
|
|
|
Supported are: Blender's .blend and the builtin exporters:\n\
|
|
|
|
|
VRML 1.0 (.wrl), Videoscape (.obj), DXF (.dxf) and STL (.stl)\n\
|
|
|
|
|
(filename) - A filename with one of the supported extensions.\n\
|
|
|
|
|
Note 1: 'filename' should not contain the substring \".B.blend\" in it.\n\
|
|
|
|
|
Note 2: only .blend raises an error if file wasn't saved.\n\
|
|
|
|
|
\tYou can use Blender.sys.exists(filename) to make sure the file was saved\n\
|
|
|
|
|
\twhen writing to one of the other formats.";
|
2004-06-24 09:43:13 +00:00
|
|
|
|
2004-05-18 03:23:45 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Python method structure definition. */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
static struct PyMethodDef Blender_methods[] = {
|
|
|
|
|
{"Set", Blender_Set, METH_VARARGS, Blender_Set_doc},
|
|
|
|
|
{"Get", Blender_Get, METH_VARARGS, Blender_Get_doc},
|
|
|
|
|
{"Redraw", Blender_Redraw, METH_VARARGS, Blender_Redraw_doc},
|
|
|
|
|
{"Quit", (PyCFunction)Blender_Quit, METH_NOARGS, Blender_Quit_doc},
|
|
|
|
|
{"Load", Blender_Load, METH_VARARGS, Blender_Load_doc},
|
2004-06-24 09:43:13 +00:00
|
|
|
{"Save", Blender_Save, METH_VARARGS, Blender_Save_doc},
|
2004-05-18 03:23:45 +00:00
|
|
|
{"ReleaseGlobalDict", &Blender_ReleaseGlobalDict,
|
|
|
|
|
METH_VARARGS, Blender_ReleaseGlobalDict_doc},
|
2004-06-06 22:42:51 +00:00
|
|
|
{NULL, NULL, 0, NULL}
|
2004-05-18 03:23:45 +00:00
|
|
|
};
|
2003-03-08 18:10:20 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-04-24 20:04:37 +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
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-04-24 20:04:37 +00:00
|
|
|
/* Function: Blender_Set */
|
|
|
|
|
/* Python equivalent: Blender.Set */
|
2003-03-08 18:10:20 +00:00
|
|
|
/*****************************************************************************/
|
2004-05-18 03:23:45 +00:00
|
|
|
static PyObject *Blender_Set (PyObject *self, PyObject *args)
|
2003-02-26 19:22:24 +00:00
|
|
|
{
|
2004-04-24 20:04:37 +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
|
|
|
|
|
{
|
2004-06-06 22:42:51 +00:00
|
|
|
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
2004-04-24 20:04:37 +00:00
|
|
|
"bad request identifier"));
|
|
|
|
|
}
|
2004-06-06 22:42:51 +00:00
|
|
|
return ( EXPP_incr_ret (Py_None) );
|
2003-02-26 19:22:24 +00:00
|
|
|
}
|
2003-03-08 18:10:20 +00:00
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-04-24 20:04:37 +00:00
|
|
|
/* Function: Blender_Get */
|
|
|
|
|
/* Python equivalent: Blender.Get */
|
2003-03-08 18:10:20 +00:00
|
|
|
/*****************************************************************************/
|
2004-05-18 03:23:45 +00:00
|
|
|
static PyObject *Blender_Get (PyObject *self, PyObject *args)
|
2003-03-08 18:10:20 +00:00
|
|
|
{
|
2004-04-24 20:04:37 +00:00
|
|
|
PyObject * object;
|
|
|
|
|
PyObject * dict;
|
|
|
|
|
char * str;
|
|
|
|
|
|
|
|
|
|
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) );
|
|
|
|
|
}
|
2004-05-22 20:25:22 +00:00
|
|
|
if (StringEqual (str, "datadir"))
|
|
|
|
|
{
|
|
|
|
|
char datadir[FILE_MAXDIR];
|
|
|
|
|
BLI_make_file_string("/", datadir, bpy_gethome(), "bpydata/");
|
|
|
|
|
if (BLI_exists(datadir)) return PyString_FromString(datadir);
|
|
|
|
|
else return EXPP_incr_ret (Py_None);
|
|
|
|
|
}
|
2004-04-24 20:04:37 +00:00
|
|
|
/* 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",
|
|
|
|
|
PyInt_FromLong (U.vrmlflag & USER_VRML_TWOSIDED));
|
|
|
|
|
|
|
|
|
|
PyDict_SetItemString (dict, "layers",
|
|
|
|
|
PyInt_FromLong (U.vrmlflag & USER_VRML_LAYERS));
|
|
|
|
|
|
|
|
|
|
PyDict_SetItemString (dict, "autoscale",
|
|
|
|
|
PyInt_FromLong (U.vrmlflag & USER_VRML_AUTOSCALE));
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2004-06-06 22:42:51 +00:00
|
|
|
return (EXPP_ReturnPyObjError (..., "message") );
|
2004-04-24 20:04:37 +00:00
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-06-06 22:42:51 +00:00
|
|
|
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
2004-04-24 20:04:37 +00:00
|
|
|
"expected string argument"));
|
|
|
|
|
}
|
|
|
|
|
|
2004-06-06 22:42:51 +00:00
|
|
|
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
|
2004-04-24 20:04:37 +00:00
|
|
|
"bad request identifier"));
|
2003-03-08 18:10:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-04-24 20:04:37 +00:00
|
|
|
/* Function: Blender_Redraw */
|
|
|
|
|
/* Python equivalent: Blender.Redraw */
|
2003-03-08 18:10:20 +00:00
|
|
|
/*****************************************************************************/
|
2004-05-18 03:23:45 +00:00
|
|
|
static PyObject *Blender_Redraw(PyObject *self, PyObject *args)
|
2003-03-08 18:10:20 +00:00
|
|
|
{
|
2004-04-24 20:04:37 +00:00
|
|
|
int wintype = SPACE_VIEW3D;
|
2003-03-08 18:10:20 +00:00
|
|
|
|
2004-04-24 20:04:37 +00:00
|
|
|
if (!PyArg_ParseTuple (args, "|i", &wintype))
|
|
|
|
|
{
|
|
|
|
|
return EXPP_ReturnPyObjError (PyExc_TypeError,
|
|
|
|
|
"expected int argument (or nothing)");
|
|
|
|
|
}
|
2003-03-08 18:10:20 +00:00
|
|
|
|
2004-04-24 20:04:37 +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
|
|
|
/*****************************************************************************/
|
2004-04-24 20:04:37 +00:00
|
|
|
/* Function: Blender_ReleaseGlobalDict */
|
|
|
|
|
/* Python equivalent: Blender.ReleaseGlobalDict */
|
|
|
|
|
/* Description: Deprecated function. */
|
2003-05-13 01:54:28 +00:00
|
|
|
/*****************************************************************************/
|
2004-05-18 03:23:45 +00:00
|
|
|
static PyObject *Blender_ReleaseGlobalDict(PyObject *self, PyObject *args)
|
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);
|
2004-04-24 20:04:37 +00:00
|
|
|
return Py_None;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2004-04-24 20:04:37 +00:00
|
|
|
/* Function: Blender_Quit */
|
|
|
|
|
/* Python equivalent: Blender.Quit */
|
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
|
|
|
/*****************************************************************************/
|
2004-05-18 03:23:45 +00:00
|
|
|
static PyObject *Blender_Quit(PyObject *self)
|
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
|
|
|
{
|
2004-05-18 03:23:45 +00:00
|
|
|
BIF_write_autosave(); /* save the current data first */
|
|
|
|
|
|
|
|
|
|
exit_usiblender(); /* renames last autosave to quit.blend */
|
|
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
/**
|
|
|
|
|
* Blender.Load
|
|
|
|
|
* loads Blender's .blend, DXF, radiogour(?), STL, Videoscape,
|
|
|
|
|
* Inventor 1.0 ASCII, VRML 1.0 asc.
|
|
|
|
|
*/
|
2004-05-18 03:23:45 +00:00
|
|
|
static PyObject *Blender_Load(PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
char *fname = NULL;
|
|
|
|
|
Script *script = NULL;
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
char str[32];
|
|
|
|
|
int file, is_blend_file = 0;
|
2004-05-18 03:23:45 +00:00
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "|s", &fname))
|
|
|
|
|
return EXPP_ReturnPyObjError(PyExc_TypeError,
|
|
|
|
|
"expected filename string or nothing (for default file) as argument");
|
|
|
|
|
|
|
|
|
|
if (fname && !BLI_exists(fname))
|
|
|
|
|
return EXPP_ReturnPyObjError(PyExc_AttributeError,
|
|
|
|
|
"requested file doesn't exist!");
|
|
|
|
|
|
|
|
|
|
/* We won't let a new .blend file be loaded if there are still other
|
|
|
|
|
* scripts running, since loading a new file will close and remove them. */
|
|
|
|
|
|
|
|
|
|
if (G.main->script.first != G.main->script.last)
|
|
|
|
|
return EXPP_ReturnPyObjError(PyExc_RuntimeError,
|
|
|
|
|
"there are other scripts running at the Scripts win, close them first!");
|
|
|
|
|
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
if (fname) {
|
|
|
|
|
file = open(fname, O_BINARY|O_RDONLY);
|
2004-05-18 03:23:45 +00:00
|
|
|
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
if (file <= 0) {
|
|
|
|
|
return EXPP_ReturnPyObjError(PyExc_RuntimeError,
|
|
|
|
|
"cannot open file!");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
read(file, str, 31);
|
|
|
|
|
close(file);
|
|
|
|
|
|
|
|
|
|
if (strncmp(str, "BLEN", 4) == 0) is_blend_file = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else is_blend_file = 1; /* .B.blend */
|
|
|
|
|
|
|
|
|
|
if (is_blend_file) {
|
|
|
|
|
/* trick: mark the script so that its script struct won't be freed after
|
|
|
|
|
* the script is executed (to avoid a double free warning on exit): */
|
|
|
|
|
script = G.main->script.first;
|
|
|
|
|
script->flags |= SCRIPT_GUI;
|
|
|
|
|
|
|
|
|
|
BIF_write_autosave(); /* for safety let's preserve the current data */
|
|
|
|
|
}
|
2004-05-18 03:23:45 +00:00
|
|
|
|
|
|
|
|
/* for safety, any filename with .B.blend is considered the default one.
|
|
|
|
|
* It doesn't seem necessary to compare file attributes (like st_ino and
|
|
|
|
|
* st_dev, according to the glibc info pages) to find out if the given
|
|
|
|
|
* filename, that may have been given with a twisted misgiving path, is the
|
|
|
|
|
* default one for sure. Taking any .B.blend file as the default is good
|
|
|
|
|
* enough here. Note: the default file requires extra clean-up done by
|
|
|
|
|
* BIF_read_homefile: freeing the user theme data. */
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
if (!fname || (strstr(fname, ".B.blend") && is_blend_file))
|
2004-05-18 03:23:45 +00:00
|
|
|
BIF_read_homefile();
|
|
|
|
|
else
|
|
|
|
|
BIF_read_file(fname);
|
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);
|
2004-04-24 20:04:37 +00:00
|
|
|
return Py_None;
|
2003-05-13 01:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
2004-06-24 09:43:13 +00:00
|
|
|
static PyObject *Blender_Save(PyObject *self, PyObject *args)
|
|
|
|
|
{
|
|
|
|
|
char *fname = NULL;
|
|
|
|
|
int overwrite = 0, len = 0;
|
|
|
|
|
char *error = NULL;
|
|
|
|
|
Library *li;
|
|
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "s|i", &fname, &overwrite))
|
|
|
|
|
return EXPP_ReturnPyObjError(PyExc_TypeError,
|
|
|
|
|
"expected filename and optional int (overwrite flag) as arguments");
|
|
|
|
|
|
|
|
|
|
for (li = G.main->library.first; li; li = li->id.next) {
|
|
|
|
|
if (BLI_streq(li->name, fname)) {
|
|
|
|
|
return EXPP_ReturnPyObjError(PyExc_AttributeError,
|
|
|
|
|
"cannot overwrite used library");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* for safety, any filename with .B.blend is considered the default one
|
|
|
|
|
* and not accepted here. */
|
|
|
|
|
if (strstr(fname, ".B.blend"))
|
|
|
|
|
return EXPP_ReturnPyObjError(PyExc_AttributeError,
|
|
|
|
|
"filename can't contain the substring \".B.blend\" in it.");
|
|
|
|
|
|
|
|
|
|
len = strlen(fname);
|
|
|
|
|
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
if (len > FILE_MAXFILE)
|
2004-06-24 09:43:13 +00:00
|
|
|
return EXPP_ReturnPyObjError(PyExc_AttributeError,
|
|
|
|
|
"filename is too long!");
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
else if (BLI_exists(fname) && !overwrite)
|
2004-06-24 09:43:13 +00:00
|
|
|
return EXPP_ReturnPyObjError(PyExc_AttributeError,
|
|
|
|
|
"file already exists and overwrite flag was not given.");
|
|
|
|
|
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
disable_where_script(1); /* to avoid error popups in the write_* functions */
|
|
|
|
|
|
|
|
|
|
if (BLI_testextensie(fname, ".blend")) {
|
|
|
|
|
if (G.fileflags & G_AUTOPACK) packAll();
|
|
|
|
|
if (!BLO_write_file(fname, G.fileflags, &error)) {
|
|
|
|
|
disable_where_script(0);
|
|
|
|
|
return EXPP_ReturnPyObjError(PyExc_SystemError, error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (BLI_testextensie(fname, ".dxf"))
|
|
|
|
|
write_dxf(fname);
|
|
|
|
|
else if (BLI_testextensie(fname, ".stl"))
|
|
|
|
|
write_stl(fname);
|
|
|
|
|
else if (BLI_testextensie(fname, ".wrl"))
|
|
|
|
|
write_vrml(fname);
|
|
|
|
|
else if (BLI_testextensie(fname, ".obj"))
|
|
|
|
|
write_videoscape(fname);
|
|
|
|
|
else {
|
|
|
|
|
disable_where_script(0);
|
|
|
|
|
return EXPP_ReturnPyObjError(PyExc_AttributeError,
|
|
|
|
|
"unknown file extension.");
|
|
|
|
|
}
|
2004-06-24 09:43:13 +00:00
|
|
|
|
New scripts:
- hotkeys, obdatacopier and renameobjectbyblock, all from Jean-Michel Soler (jms);
- bevel_center by Loic Berthe, suggested for inclusion by jms;
- doc_browser, by Daniel Dunbar (Zr)
Thanks to them for the new contributions!
(I included doc_browser at 'Misc' because only users interested in script writing would actually use it, but it could also be under 'Help'. Opinions?)
BPython related:
- Added scriptlink methods to object, lamp, camera and world.
- Object: added object.makeTrack and object.clearTrack (old track method).
- sys: made sys.exists(path) return 0 for not found; 1 for file, 2 for dir and -1 for neither.
- doc updates and fixes.
- made ONLOAD event work. G.f's SCENESCRIPT bit was being zeroed in set_app_data.
- Blender: updated functions Load and Save to support the builtin importers and exporters besides .blend (dxf, videoscape, vrml 1.0, stl, ...)
- Draw: added mouse wheel events.
- Scene: added scene.play to play back animations (like ALT+A and SHIFT+ALT+A). Makes a good counter, too, when the 'win' attribute is set to a space that doesn't "animate".
The scene.play() addition and the fix to ONLOAD scriptlinks is part of the work for a Blender demo mode. It already works, but I'll still add support for Radiosity calculations and fix a thing in main(): it executes onload scripts too early (BIF_Init), giving funny results in alt+a animations and renderings when firing up Blender. Loading after the program is up has no such problems. When I finish I'll post examples of demo mode scripts.
2004-07-03 05:17:04 +00:00
|
|
|
disable_where_script(0);
|
2004-06-24 09:43:13 +00:00
|
|
|
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
|
return Py_None;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-08 18:10:20 +00:00
|
|
|
/*****************************************************************************/
|
2004-04-24 20:04:37 +00:00
|
|
|
/* Function: initBlender */
|
2003-03-08 18:10:20 +00:00
|
|
|
/*****************************************************************************/
|
2003-05-17 13:46:15 +00:00
|
|
|
void M_Blender_Init (void)
|
2003-03-08 18:10:20 +00:00
|
|
|
{
|
2004-04-24 20:04:37 +00:00
|
|
|
PyObject * module;
|
|
|
|
|
PyObject * dict;
|
2003-06-28 07:38:21 +00:00
|
|
|
|
2004-04-24 20:04:37 +00:00
|
|
|
g_blenderdict = NULL;
|
2003-06-28 07:38:21 +00:00
|
|
|
|
2004-04-24 20:04:37 +00:00
|
|
|
/* TODO: create a docstring for the Blender module */
|
|
|
|
|
module = Py_InitModule3("Blender", Blender_methods, NULL);
|
2003-06-28 07:38:21 +00:00
|
|
|
|
2004-04-23 13:11:48 +00:00
|
|
|
types_InitAll(); /* set all our pytypes to &PyType_Type*/
|
|
|
|
|
|
2004-04-24 20:04:37 +00:00
|
|
|
dict = PyModule_GetDict (module);
|
|
|
|
|
g_blenderdict = dict;
|
2004-05-04 14:27:41 +00:00
|
|
|
|
|
|
|
|
Py_INCREF(Py_False);
|
|
|
|
|
PyDict_SetItemString(dict, "bylink", Py_False);
|
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
|
PyDict_SetItemString(dict, "link", Py_None);
|
|
|
|
|
PyDict_SetItemString(dict, "event", PyString_FromString(""));
|
|
|
|
|
|
2004-04-24 20:04:37 +00:00
|
|
|
PyDict_SetItemString (dict, "Types", Types_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "sys", sys_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Registry", Registry_Init());
|
|
|
|
|
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());
|
|
|
|
|
PyDict_SetItemString (dict, "Lattice", Lattice_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Curve", Curve_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Armature", Armature_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Ipo", Ipo_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "IpoCurve", IpoCurve_Init());
|
|
|
|
|
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());
|
|
|
|
|
PyDict_SetItemString (dict, "Texture", Texture_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "NMesh", NMesh_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Noise", Noise_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Mathutils",Mathutils_Init());
|
|
|
|
|
PyDict_SetItemString (dict, "Library", Library_Init());
|
2004-04-25 05:18:43 +00:00
|
|
|
|
|
|
|
|
PyModule_AddIntConstant(module, "TRUE", 1);
|
|
|
|
|
PyModule_AddIntConstant(module, "FALSE", 0);
|
2003-03-08 18:10:20 +00:00
|
|
|
}
|