new python module constants

* bpy.home - result of BLI_gethome()
* bpy.version - BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION
* bpy.version_string, as above, formatted: "%d.%02d (sub %d)"
This commit is contained in:
Campbell Barton 2009-12-28 10:00:04 +00:00
parent 5f329190c9
commit 98f1d6957e
5 changed files with 22 additions and 29 deletions

@ -651,8 +651,8 @@ def write(filename, batch_objects = None, \
}''' % (curtime)) }''' % (curtime))
file.write('\nCreationTime: "%.4i-%.2i-%.2i %.2i:%.2i:%.2i:000"' % curtime) file.write('\nCreationTime: "%.4i-%.2i-%.2i %.2i:%.2i:%.2i:000"' % curtime)
file.write('\nCreator: "Blender3D version 2.5"') file.write('\nCreator: "Blender3D version %s"' % bpy.version_string)
# file.write('\nCreator: "Blender3D version %.2f"' % Blender.Get('version'))
pose_items = [] # list of (fbxName, matrix) to write pose data for, easier to collect allong the way pose_items = [] # list of (fbxName, matrix) to write pose data for, easier to collect allong the way

@ -40,29 +40,6 @@ All objects that can be represented as a mesh (mesh, curve, metaball, surface, t
will be exported as mesh data. will be exported as mesh data.
""" """
# --------------------------------------------------------------------------
# OBJ Export v1.1 by Campbell Barton (AKA Ideasman)
# --------------------------------------------------------------------------
# ***** BEGIN GPL 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.
#
# 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.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------
# import math and other in functions that use them for the sake of fast Blender startup # import math and other in functions that use them for the sake of fast Blender startup
# import math # import math
import os import os
@ -384,8 +361,7 @@ def write(filename, objects, scene,
file = open(filename, "w") file = open(filename, "w")
# Write Header # Write Header
version = "2.5" file.write('# Blender3D v%s OBJ File: %s\n' % (bpy.version_string, bpy.data.filename.split('/')[-1].split('\\')[-1] ))
file.write('# Blender3D v%s OBJ File: %s\n' % (version, bpy.data.filename.split('/')[-1].split('\\')[-1] ))
file.write('# www.blender3d.org\n') file.write('# www.blender3d.org\n')
# Tell the obj file what material file to use. # Tell the obj file what material file to use.

@ -205,8 +205,7 @@ def write(filename, scene, ob, \
file.write('ply\n') file.write('ply\n')
file.write('format ascii 1.0\n') file.write('format ascii 1.0\n')
version = "2.5" # Blender.Get('version') file.write('comment Created by Blender3D %s - www.blender.org, source file: %s\n' % (bpy.version_string, bpy.data.filename.split('/')[-1].split('\\')[-1]))
file.write('comment Created by Blender3D %s - www.blender.org, source file: %s\n' % (version, bpy.data.filename.split('/')[-1].split('\\')[-1]))
file.write('element vertex %d\n' % len(ply_verts)) file.write('element vertex %d\n' % len(ply_verts))
@ -327,3 +326,4 @@ bpy.types.INFO_MT_file_export.append(menu_func)
if __name__ == "__main__": if __name__ == "__main__":
bpy.ops.export.ply(path="/tmp/test.ply") bpy.ops.export.ply(path="/tmp/test.ply")

@ -99,4 +99,10 @@ def _main():
else: else:
load_scripts() load_scripts()
# constants
version = _bpy._VERSION
version_string = _bpy._VERSION_STR
home = _bpy._HOME
_main() _main()

@ -59,6 +59,7 @@
#include "BLI_fileops.h" #include "BLI_fileops.h"
#include "BLI_string.h" #include "BLI_string.h"
#include "BKE_blender.h"
#include "BKE_context.h" #include "BKE_context.h"
#include "BKE_text.h" #include "BKE_text.h"
#include "BKE_context.h" #include "BKE_context.h"
@ -220,6 +221,16 @@ static void bpy_init_modules( void )
PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module); PyModule_AddObject(mod, "context", (PyObject *)bpy_context_module);
} }
/* blender info that wont change at runtime, add into _bpy */
{
PyObject *mod_dict= PyModule_GetDict(mod);
char tmpstr[256];
PyModule_AddStringConstant(mod, "_HOME", BLI_gethome());
PyDict_SetItemString(mod_dict, "_VERSION", Py_BuildValue("(iii)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION));
sprintf(tmpstr, "%d.%02d (sub %d)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION);
PyModule_AddStringConstant(mod, "_VERSION_STR", tmpstr);
}
/* add our own modules dir, this is a python package */ /* add our own modules dir, this is a python package */
bpy_import_test("bpy"); bpy_import_test("bpy");
} }