- small updates to scripts and bpython docs, also fixed two warnings;

- added function Blender.sys.exists(path) to check if a given file exists;
- forgot to mention: in my previous commit the blender.html file was also updated slightly.
This commit is contained in:
Willian Padovani Germano
2004-06-10 15:14:49 +00:00
parent a6d077bae2
commit a23c6a71da
8 changed files with 209 additions and 172 deletions

View File

@@ -333,7 +333,9 @@ def motion2bvh(frame, chennelList, nodeObjectList):
return motionData return motionData
def saveBVH(filename): def saveBVH(filename):
if filename.find('.bvh', -4) <= 0: filename += '.bvh' # for safety
# Here we store a serialized list of blender objects as they appier # Here we store a serialized list of blender objects as they appier
# in the hierarchy, this is refred to when writing motiondata # in the hierarchy, this is refred to when writing motiondata
nodeObjectList = [] nodeObjectList = []

View File

@@ -65,7 +65,9 @@ from Blender import *
NULL_MAT = '(null)' NULL_MAT = '(null)'
def save_obj(filename): def save_obj(filename):
if filename.find('.obj', -4) <= 0: filename += '.obj' # for safety
file = open(filename, "w") file = open(filename, "w")
# Write Header # Write Header

View File

@@ -35,9 +35,11 @@
#include "Object.h" #include "Object.h"
#include "NLA.h" #include "NLA.h"
#include "blendef.h" #include <blendef.h>
#include "DNA_scene_types.h" #include <DNA_scene_types.h>
#include "BSE_edit.h" #include <BSE_edit.h>
#include <BKE_mball.h>
#include <BIF_editview.h>
/*****************************************************************************/ /*****************************************************************************/
/* Python API function prototypes for the Blender module. */ /* Python API function prototypes for the Blender module. */

View File

@@ -29,10 +29,67 @@
* ***** END GPL/BL DUAL LICENSE BLOCK ***** * ***** END GPL/BL DUAL LICENSE BLOCK *****
*/ */
#include "BKE_utildefines.h" #include <BKE_utildefines.h>
#include "PIL_time.h" #include <BLI_blenlib.h>
#include <PIL_time.h>
#include <Python.h>
#include "gen_utils.h"
#include "modules.h"
#include "Sys.h" /*****************************************************************************/
/* Python API function prototypes for the sys module. */
/*****************************************************************************/
static PyObject *M_sys_basename (PyObject *self, PyObject *args);
static PyObject *M_sys_dirname (PyObject *self, PyObject *args);
static PyObject *M_sys_splitext (PyObject *self, PyObject *args);
static PyObject *M_sys_exists (PyObject *self, PyObject *args);
static PyObject *M_sys_time (PyObject *self);
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.sys.__doc__ */
/*****************************************************************************/
static char M_sys_doc[] =
"The Blender.sys submodule\n\
\n\
This is a minimal system module to supply simple functionality available\n\
in the default Python module os.";
static char M_sys_basename_doc[] =
"(path) - Split 'path' in dir and filename.\n\
Return the filename.";
static char M_sys_dirname_doc[] =
"(path) - Split 'path' in dir and filename.\n\
Return the dir.";
static char M_sys_splitext_doc[] =
"(path) - Split 'path' in root and extension:\n\
/this/that/file.ext -> ('/this/that/file','.ext').\n\
Return the pair (root, extension).";
static char M_sys_time_doc[] =
"() - Return a float representing time elapsed in seconds.\n\
Each successive call is garanteed to return values greater than or\n\
equal to the previous call.";
static char M_sys_exists_doc[] =
"(path) - Return 1 if given pathname (file or dir) exists, 0 otherwise.";
/*****************************************************************************/
/* Python method structure definition for Blender.sys module: */
/*****************************************************************************/
struct PyMethodDef M_sys_methods[] = {
{"basename", M_sys_basename, METH_VARARGS, M_sys_basename_doc},
{"dirname", M_sys_dirname, METH_VARARGS, M_sys_dirname_doc},
{"splitext", M_sys_splitext, METH_VARARGS, M_sys_splitext_doc},
{"exists", M_sys_exists, METH_VARARGS, M_sys_exists_doc},
{"time", (PyCFunction)M_sys_time, METH_NOARGS, M_sys_time_doc},
{NULL, NULL, 0, NULL}
};
/* Module Functions */
static PyObject *g_sysmodule = NULL; /* pointer to Blender.sys module */ static PyObject *g_sysmodule = NULL; /* pointer to Blender.sys module */
@@ -176,3 +233,18 @@ static PyObject *M_sys_time (PyObject *self)
return Py_BuildValue("d", t); return Py_BuildValue("d", t);
} }
static PyObject *M_sys_exists (PyObject *self, PyObject *args)
{
char *fname = NULL;
int i = 0;
if (!PyArg_ParseTuple(args, "s", &fname))
return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string (file path) argument");
i = BLI_exists(fname);
if (i) return Py_BuildValue("i", 1); /* path was found */
return Py_BuildValue("i", 0); /* path doesn't exist */
}

View File

@@ -32,54 +32,4 @@
#ifndef EXPP_sys_H #ifndef EXPP_sys_H
#define EXPP_sys_H #define EXPP_sys_H
#include <Python.h>
#include <BLI_blenlib.h> /* for BLI_last_slash() */
#include "gen_utils.h"
#include "modules.h"
/*****************************************************************************/
/* Python API function prototypes for the sys module. */
/*****************************************************************************/
static PyObject *M_sys_basename (PyObject *self, PyObject *args);
static PyObject *M_sys_dirname (PyObject *self, PyObject *args);
static PyObject *M_sys_splitext (PyObject *self, PyObject *args);
static PyObject *M_sys_time (PyObject *self);
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.sys.__doc__ */
/*****************************************************************************/
static char M_sys_doc[] =
"The Blender.sys submodule\n\
\n\
This is a minimal system module to supply simple functionality available\n\
in the default Python module os.";
static char M_sys_basename_doc[]="(path) - Split 'path' in dir and filename.\n\
Return the filename.";
static char M_sys_dirname_doc[]="(path) - Split 'path' in dir and filename.\n\
Return the dir.";
static char M_sys_splitext_doc[]="(path) - Split 'path' in root and \
extension:\n/this/that/file.ext -> ('/this/that/file','.ext').\n\
Return the pair (root, extension).";
static char M_sys_time_doc[]="() - Return a float representing time elapsed \
in seconds.\n\
Each successive call is garanteed to return values greater than or\n\
equal to the previous call.";
/*****************************************************************************/
/* Python method structure definition for Blender.sys module: */
/*****************************************************************************/
struct PyMethodDef M_sys_methods[] = {
{"basename", M_sys_basename, METH_VARARGS, M_sys_basename_doc},
{"dirname", M_sys_dirname, METH_VARARGS, M_sys_dirname_doc},
{"splitext", M_sys_splitext, METH_VARARGS, M_sys_splitext_doc},
{"time", (PyCFunction)M_sys_time, METH_NOARGS, M_sys_time_doc},
{NULL, NULL, 0, NULL}
};
#endif /* EXPP_sys_H */ #endif /* EXPP_sys_H */

View File

@@ -21,7 +21,7 @@ The Blender Python API Reference
- L{Armature} - L{Armature}
- L{Bone} - L{Bone}
- L{NLA} (new) - L{NLA}
- L{BGL} - L{BGL}
- L{Camera} - L{Camera}
- L{Curve} - L{Curve}
@@ -31,22 +31,22 @@ The Blender Python API Reference
- L{Ipo} - L{Ipo}
- L{Lamp} - L{Lamp}
- L{Lattice} - L{Lattice}
- L{Library} (new) - L{Library}
- L{Material} - L{Material}
- L{Mathutils} (new) - L{Mathutils}
- L{Metaball} - L{Metaball}
- L{NMesh} - L{NMesh}
- L{Noise} (new) - L{Noise}
- L{Object} - L{Object}
- L{Registry} - L{Registry}
- L{Scene} - L{Scene}
- L{Render} (new) - L{Render}
- L{Text} - L{Text}
- L{Texture} - L{Texture}
- L{Types} - L{Types}
- L{Window} - L{Window}
- L{World} - L{World}
- L{sys<Sys>} (added time function) - L{sys<Sys>}
Introduction: Introduction:
------------- -------------

View File

@@ -5,16 +5,16 @@ The Blender.Metaball submodule
This module provides access to the B{Metaball Data} in Blender. This module provides access to the B{Metaball Data} in Blender.
Example: Example::
import Blender import Blender
ob = Blender.Object.New("Mball","mb") ob = Blender.Object.New("Mball","mb")
mb = Blender.Metaball.New() mb = Blender.Metaball.New()
for i in range(20): for i in range(20):
mb.addMetaelem([0, float(i),1.0,1.0, 2.0,1,2.0,1.0,1.0,1.0]) mb.addMetaelem([0, float(i),1.0,1.0, 2.0,1,2.0,1.0,1.0,1.0])
ob.link(mb) ob.link(mb)
sc = Blender.Scene.getCurrent() sc = Blender.Scene.getCurrent()
sc.link(ob) sc.link(ob)
""" """
@@ -38,7 +38,6 @@ def Get (name):
- (): A list with all Metaballs in the current scene. - (): A list with all Metaballs in the current scene.
""" """
class Metaball: class Metaball:
""" """
The Metaball object The Metaball object
@@ -49,157 +48,158 @@ class Metaball:
@cvar rot: The rotation of the metaball. @cvar rot: The rotation of the metaball.
@cvar size: The size of the metaball. @cvar size: The size of the metaball.
""" """
def addMetaelem(paramslist):
"""
Sets the name of a metaball object
@type name: list
@param name : the list of the parameters for creating a new metaelem
This list has ten elements :
param 1 : int : metaelem type
0 for a sphere
1 for a tubex
2 for a tubey
3 for a tubez
4 for a regular tube
5 for a plane
6 for an ellipsoid
7 for a cube
params 2,3,4 : floats, the x, y and z coordinates of the metaelem
param 5 : float, the rad value of the metaelem
param 6 : int, the lay value.
param 7 : float the s value of the metaelem
params 8,9,10 : the expx, expy and expz values of the metaelem.
@rtype: PyNone def addMetaelem(paramslist):
@return: PyNone
""" """
Add a new metaelem to this metaball. 'paramslist' must have the
following ten elements:
- param 1: int - metaelem type:
- 0 for a sphere
- 1 for a tubex
- 2 for a tubey
- 3 for a tubez
- 4 for a regular tube
- 5 for a plane
- 6 for an ellipsoid
- 7 for a cube
- params 2,3,4: floats - the x, y and z coordinates of the metaelem.
- param 5: float - the rad value of the metaelem.
- param 6: int - the lay value.
- param 7: float - the s value of the metaelem.
- params 8,9,10: floats - the expx, expy and expz values of the metaelem.
@type paramslist: list
@param paramslist: the list of the parameters for creating a new metaelem.
@rtype: None
@return: None
"""
def getName(): def getName():
""" """
Retreives the name of a metaball object Retrieves the name of a metaball object.
@rtype: string @rtype: string
@return: the name of a metaball object @return: the name of a metaball object.
""" """
def setName(name): def setName(name):
""" """
Sets the name of a metaball object Sets the name of a metaball object.
@type name: string @type name: string
@param name : the new name @param name : the new name
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getBbox(): def getBbox():
""" """
Retreives the bounding box of a metaball object Retrieves the bounding box of a metaball object.
@rtype: a list of 24 floats(8 points, 3 coordinates) @rtype: a list of 24 floats(8 points, 3 coordinates)
@return: the bounding box of a metaball object @return: the bounding box of a metaball object
""" """
def getNMetaElems(): def getNMetaElems():
""" """
Retreives the number of metaelems (elementary spheres or cylinders) of a metaball object Retrieves the number of metaelems (elementary spheres or cylinders) of a metaball object.
@rtype: int @rtype: int
@return: number of metaelems of a metaball object @return: number of metaelems of a metaball object
""" """
def getLoc(): def getLoc():
""" """
Retreives the location of a metaball object Retrieves the location of a metaball object.
@rtype: a list of 3 floats @rtype: a list of 3 floats
@return: locationof a metaball object @return: location of a metaball object
""" """
def setLoc(newloc): def setLoc(newloc):
""" """
Sets the location of a metaball object Sets the location of a metaball object.
@type newloc: list of 3 floats @type newloc: list of 3 floats
@param newloc: the new location @param newloc: the new location
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getRot(): def getRot():
""" """
Retreives the rotation of a metaball object Retrieves the rotation of a metaball object.
@rtype: a list of 3 floats @rtype: a list of 3 floats
@return: rotationof a metaball object @return: rotation of a metaball object
""" """
def setRot(newrot): def setRot(newrot):
""" """
Sets the rotation of a metaball object Sets the rotation of a metaball object.
@type newrot: list of 3 floats @type newrot: list of 3 floats
@param newrot: the new rotation @param newrot: the new rotation
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getSize(): def getSize():
""" """
Retreives the size of a metaball object Retrieves the size of a metaball object.
@rtype: a list of 3 floats @rtype: a list of 3 floats
@return: size a metaball object @return: size a metaball object
""" """
def setSize(newsize): def setSize(newsize):
""" """
Sets the size of a metaball object Sets the size of a metaball object.
@type newsize: list of 3 floats @type newsize: list of 3 floats
@param newsize: the new size @param newsize: the new size
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getWiresize(): def getWiresize():
""" """
Retreives the wiresize of a metaball object Retrieves the wiresize of a metaball object.
@rtype: float @rtype: float
@return: wire size a metaball object @return: wire size a metaball object
""" """
def setWiresize(newsize): def setWiresize(newsize):
""" """
Sets the wire size of a metaball object Sets the wire size of a metaball object.
@type newsize: float @type newsize: float
@param newsize: the new size @param newsize: the new size
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getRendersize(): def getRendersize():
""" """
Retreives the rendersize of a metaball object Retrieves the rendersize of a metaball object.
@rtype: float @rtype: float
@return: render size a metaball object @return: render size a metaball object
""" """
def setRendersize(newsize): def setRendersize(newsize):
""" """
Sets the render size of a metaball object Sets the render size of a metaball object.
@type newsize: float @type newsize: float
@param newsize: the new size @param newsize: the new size
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getThresh(): def getThresh():
""" """
Retreives the threshold of a metaball object Retrieves the threshold of a metaball object.
@rtype: float @rtype: float
@return: threshold of the metaball object @return: threshold of the metaball object
""" """
def setThresh(threshold): def setThresh(threshold):
""" """
Sets the threshold of a metaball object Sets the threshold of a metaball object.
@type threshold: float @type threshold: float
@param threshold: the new size @param threshold: the new size
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getMetadata(name,num): def getMetadata(name,num):
@@ -215,134 +215,134 @@ class Metaball:
def setMetadata(name,num,val): def setMetadata(name,num,val):
""" """
The setMetadata function has the same semantics as getMetadata, except that it needs the parameter value, and always returns PyNone. The setMetadata function has the same semantics as getMetadata, except that it needs the parameter value, and always returns None.
@type name: string @type name: string
@param name: the name of the property to be read. The accepted values are :"type", "x", "y", "z", "expx", "expy", "expz", "rad", "rad2", "s", "len". @param name: the name of the property to be read. The accepted values are :"type", "x", "y", "z", "expx", "expy", "expz", "rad", "rad2", "s", "len".
@type num: int @type num: int
@param num: the position of the metaelem to be accessed. @param num: the position of the metaelem to be accessed.
@type val: float, except if name is "type". @type val: float, except if name is "type".
@param val: the new value of the parameter. @param val: the new value of the parameter.
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getMetatype(pos): def getMetatype(pos):
""" """
Retreives the type of a metaelem object Retrieves the type of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@rtype: int @rtype: int
@return: type of the metaelem object @return: type of the metaelem object
""" """
def setMetatype(pos,newtype): def setMetatype(pos,newtype):
""" """
Sets the type of a metaelem object Sets the type of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@type newtype: int @type newtype: int
@param newtype: the new type @param newtype: the new type
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getMetax(pos): def getMetax(pos):
""" """
Retreives the x parameter of a metaelem object Retrieves the x parameter of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@rtype: float @rtype: float
@return: x parameter of the metaelem object @return: x parameter of the metaelem object
""" """
def setMetax(pos,newx): def setMetax(pos,newx):
""" """
Sets the x parameter of a metaelem object Sets the x parameter of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@type newx: float @type newx: float
@param newx: the new x parameter value @param newx: the new x parameter value
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getMetay(pos): def getMetay(pos):
""" """
Retreives the y parameter of a metaelem object Retrieves the y parameter of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@rtype: float @rtype: float
@return: y parameter of the metaelem object @return: y parameter of the metaelem object
""" """
def setMetay(pos,newy): def setMetay(pos,newy):
""" """
Sets the y parameter of a metaelem object Sets the y parameter of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@type newy: float @type newy: float
@param newy: the new y parameter value @param newy: the new y parameter value
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getMetaz(pos): def getMetaz(pos):
""" """
Retreives the z parameter of a metaelem object Retrieves the z parameter of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@rtype: float @rtype: float
@return: z parameter of the metaelem object @return: z parameter of the metaelem object
""" """
def setMetaz(pos,newz): def setMetaz(pos,newz):
""" """
Sets the z parameter of a metaelem object Sets the z parameter of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@type newz: float @type newz: float
@param newz: the new z parameter value @param newz: the new z parameter value
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getMetas(pos): def getMetas(pos):
""" """
Retreives the s parameter of a metaelem object Retrieves the s parameter of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@rtype: float @rtype: float
@return: s parameter of the metaelem object @return: s parameter of the metaelem object
""" """
def setMetas(pos,news): def setMetas(pos,news):
""" """
Sets the s parameter of a metaelem object Sets the s parameter of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@type news: float @type news: float
@param news: the new x parameter value @param news: the new x parameter value
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """
def getMetalen(pos): def getMetalen(pos):
""" """
Retreives the len parameter of a metaelem object Retrieves the len parameter of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@rtype: float @rtype: float
@return: len parameter of the metaelem object @return: len parameter of the metaelem object
""" """
def setMetalen(pos,newlen): def setMetalen(pos,newlen):
""" """
Sets the len parameter of a metaelem object Sets the len parameter of a metaelem object.
@type pos: int @type pos: int
@param : the position of the metaelement @param pos: the position of the metaelement
@type newlen: float @type newlen: float
@param newlen: the new x parameter value @param newlen: the new x parameter value
@rtype: PyNone @rtype: None
@return: PyNone @return: None
""" """

View File

@@ -6,7 +6,7 @@ The Blender.sys submodule.
sys sys
=== ===
B{New}: L{time} B{New}: L{exists}
This module provides a minimal set of helper functions and data. Its purpose This module provides a minimal set of helper functions and data. Its purpose
is to avoid the need for the standard Python module 'os', in special 'os.path', is to avoid the need for the standard Python module 'os', in special 'os.path',
@@ -28,6 +28,8 @@ Example::
print 'dirname:', Blender.sys.dirname(filename) print 'dirname:', Blender.sys.dirname(filename)
print 'splitext:', Blender.sys.splitext(filename) print 'splitext:', Blender.sys.splitext(filename)
# what would basename(splitext(filename)[0]) print?
@type sep: char @type sep: char
@var sep: the platform-specific dir separator for this Blender: '/' @var sep: the platform-specific dir separator for this Blender: '/'
everywhere, except on Win systems, that use '\\'. everywhere, except on Win systems, that use '\\'.
@@ -66,6 +68,13 @@ def splitext (path):
@return: (root, ext) @return: (root, ext)
""" """
def exists(path):
"""
Tell if the given pathname (file or dir) exists.
@rtype: bool
@return: 1 if 'path' exists, 0 otherwise.
"""
def time (): def time ():
""" """
Get the current time in seconds since a fixed value. Successive calls to Get the current time in seconds since a fixed value. Successive calls to