2004-01-23 19:24:45 +00:00
|
|
|
# Blender.sys module
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
The Blender.sys submodule.
|
|
|
|
|
|
|
|
|
|
sys
|
|
|
|
|
===
|
|
|
|
|
|
BPython:
- new submodule Scene.Radio, for radiosity: still incomplete, but in shape for demos, updated SConscript to include it;
- new functions in Window module;
- doc updates: adding a todo file and a new start page for our docs: API_intro.py + other updates;
- small fix in Ipo.c provided by Damien McGuinnes (thanks!): Nathan has a patch with IPO additions and fixes for this and more, but until it is committed, there's this fix for Ipo.getCurve('LocX'), LocY, Z and QuatW,X,Y,Z too, according to Damien.
Other files:
- radpreprocess.c: added check for "during_script()" so eventual msgs don't popup during scripts;
- drawmesh.c: made a pointer (display list) be checked before accessed, fixes crash in scripts that forget to update display lists for subsurf meshes when a 3d view is in textured view mode.
Script: updated bevel_center by Loic Berthe.
2004-07-25 16:55:45 +00:00
|
|
|
B{New}: L{exists}, L{makename}, L{join}, L{sleep}.
|
2004-04-24 20:04:37 +00:00
|
|
|
|
2004-01-23 19:24:45 +00:00
|
|
|
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',
|
|
|
|
|
though it is only meant for the simplest cases.
|
|
|
|
|
|
|
|
|
|
Example::
|
|
|
|
|
|
|
|
|
|
import Blender
|
|
|
|
|
|
|
|
|
|
filename = ""
|
|
|
|
|
def f(name): # file selector callback
|
|
|
|
|
global filename
|
|
|
|
|
filename = name
|
|
|
|
|
|
|
|
|
|
Blender.Window.FileSelector(f)
|
|
|
|
|
|
|
|
|
|
if filename:
|
|
|
|
|
print 'basename:', Blender.sys.basename(filename)
|
|
|
|
|
print 'dirname:', Blender.sys.dirname(filename)
|
|
|
|
|
print 'splitext:', Blender.sys.splitext(filename)
|
|
|
|
|
|
2004-06-10 15:14:49 +00:00
|
|
|
# what would basename(splitext(filename)[0]) print?
|
|
|
|
|
|
2004-01-23 19:24:45 +00:00
|
|
|
@type sep: char
|
|
|
|
|
@var sep: the platform-specific dir separator for this Blender: '/'
|
|
|
|
|
everywhere, except on Win systems, that use '\\'.
|
|
|
|
|
@type dirsep: char
|
|
|
|
|
@var dirsep: same as L{sep}.
|
|
|
|
|
@type progname: string
|
|
|
|
|
@var progname: the Blender executable (argv[0]).
|
|
|
|
|
|
|
|
|
|
@attention: The module is called sys, not Sys.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def basename (path):
|
|
|
|
|
"""
|
|
|
|
|
Get the base name (filename stripped from dir info) of 'path'.
|
|
|
|
|
@type path: string
|
|
|
|
|
@param path: a path name
|
|
|
|
|
@rtype: string
|
|
|
|
|
@return: the base name
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def dirname (path):
|
|
|
|
|
"""
|
|
|
|
|
Get the dir name (dir path stripped from filename) of 'path'.
|
|
|
|
|
@type path: string
|
|
|
|
|
@param path: a path name
|
|
|
|
|
@rtype: string
|
|
|
|
|
@return: the dir name
|
|
|
|
|
"""
|
|
|
|
|
|
2004-06-24 15:03:08 +00:00
|
|
|
def join (dir, file):
|
|
|
|
|
"""
|
|
|
|
|
Join the given dir and file paths, using the proper separator for each
|
|
|
|
|
platform.
|
|
|
|
|
@type dir: string
|
|
|
|
|
@type file: string
|
|
|
|
|
@param dir: the dir name, like returned from L{dirname}.
|
|
|
|
|
@param file: the bare filename, like returned from L{basename}.
|
|
|
|
|
@rtype: string
|
|
|
|
|
@return: the resulting filename.
|
|
|
|
|
@warn: this simple function isn't intended to be a complete replacement for
|
|
|
|
|
the standard os.path.join() one, which handles more general cases.
|
|
|
|
|
"""
|
|
|
|
|
|
2004-01-23 19:24:45 +00:00
|
|
|
def splitext (path):
|
|
|
|
|
"""
|
|
|
|
|
Split 'path' into (root, ext), where 'ext' is a file extension.
|
|
|
|
|
@type path: string
|
|
|
|
|
@param path: a path name
|
|
|
|
|
@rtype: list with two strings
|
|
|
|
|
@return: (root, ext)
|
|
|
|
|
"""
|
2004-04-24 20:04:37 +00:00
|
|
|
|
2004-06-15 04:16:30 +00:00
|
|
|
def makename (path = "Blender.Get('filename')", ext = "", strip = 0):
|
|
|
|
|
"""
|
|
|
|
|
Remove extension from 'path', append extension 'ext' (if given)
|
|
|
|
|
to the result and return it. If 'strip' is non-zero, also remove
|
|
|
|
|
dirname from path.
|
|
|
|
|
|
|
|
|
|
Example::
|
|
|
|
|
import Blender
|
|
|
|
|
from Blender.sys import *
|
|
|
|
|
print makename('/path/to/myfile.txt','.abc', 1) # returns 'myfile.abc'
|
|
|
|
|
|
|
|
|
|
print makename('/path/to/myfile.obj', '-01.obj') # '/path/to/myfile-01.obj'
|
|
|
|
|
|
|
|
|
|
print makename('/path/to/myfile.txt', strip = 1) # 'myfile'
|
|
|
|
|
|
|
|
|
|
# note that:
|
|
|
|
|
print makename(ext = '.txt')
|
|
|
|
|
# is equivalent to:
|
|
|
|
|
print sys.splitext(Blender.Get('filename'))[0]) + '.txt'
|
|
|
|
|
|
|
|
|
|
@type path: string
|
|
|
|
|
@param path: a path name or Blender.Get('filename'), if not given.
|
|
|
|
|
@type ext: string
|
|
|
|
|
@param ext: an extension to append. For flexibility, a dot ('.') is
|
|
|
|
|
not automatically included.
|
|
|
|
|
@rtype: string
|
|
|
|
|
@return: the resulting string
|
|
|
|
|
"""
|
|
|
|
|
|
2004-06-10 15:14:49 +00:00
|
|
|
def exists(path):
|
|
|
|
|
"""
|
|
|
|
|
Tell if the given pathname (file or dir) exists.
|
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
|
|
|
@rtype: int
|
|
|
|
|
@return:
|
|
|
|
|
- 0: path does not exist;
|
|
|
|
|
- 1: path is an existing filename;
|
|
|
|
|
- 2: path is an existing dirname;
|
|
|
|
|
- -1: path exists but is neither a regular file nor a dir.
|
2004-06-10 15:14:49 +00:00
|
|
|
"""
|
|
|
|
|
|
2004-04-24 20:04:37 +00:00
|
|
|
def time ():
|
|
|
|
|
"""
|
|
|
|
|
Get the current time in seconds since a fixed value. Successive calls to
|
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
|
|
|
this function are guaranteed to return values greater than the previous call.
|
2004-04-24 20:04:37 +00:00
|
|
|
@rtype: float
|
|
|
|
|
@return: the elapsed time in seconds.
|
|
|
|
|
"""
|
BPython:
- new submodule Scene.Radio, for radiosity: still incomplete, but in shape for demos, updated SConscript to include it;
- new functions in Window module;
- doc updates: adding a todo file and a new start page for our docs: API_intro.py + other updates;
- small fix in Ipo.c provided by Damien McGuinnes (thanks!): Nathan has a patch with IPO additions and fixes for this and more, but until it is committed, there's this fix for Ipo.getCurve('LocX'), LocY, Z and QuatW,X,Y,Z too, according to Damien.
Other files:
- radpreprocess.c: added check for "during_script()" so eventual msgs don't popup during scripts;
- drawmesh.c: made a pointer (display list) be checked before accessed, fixes crash in scripts that forget to update display lists for subsurf meshes when a 3d view is in textured view mode.
Script: updated bevel_center by Loic Berthe.
2004-07-25 16:55:45 +00:00
|
|
|
|
|
|
|
|
def sleep (millisecs = 10):
|
|
|
|
|
"""
|
|
|
|
|
Sleep for the specified amount of time.
|
|
|
|
|
@type millisecs: int
|
|
|
|
|
@param millisecs: the amount of time in milliseconds to sleep. The default
|
|
|
|
|
is 10 which is 0.1 seconds.
|
|
|
|
|
"""
|