Scripts: - Thanks Jean-Michel Soler (jms) for updated versions of dispaint, fixfromarmature and unweld (also renamed to remove version part). - Thanks Bart for the upgraded VRML exporter (great doc webpage!). It is available as VRML 97 and the original VRML 2 is for now still there, to help users testing the new version. For the next release the old one should be removed, of course. - New script: Scripts Config Editor (Scripts win -> Scripts -> System). Scripts with config options (simple data that is to be set according to user needs or preferences) can use this facility instead of providing a gui and writing config files to disk themselves. - Added new menu: System, available in the Scripts win. - Updated sys_info.py, help_browse.py and the AC3D importer and exporter. - Removed use of the Scrollbar and added arrow keys and mouse wheel support instead in Daniel Dunbar's old doc_browser.py. The scrollbar events handling doesn't exist, Ton suggested removing the scrollbar from the API months ago. For now its ref doc is gone and no bundled script uses it, until we get time to implement it properly. - Added module BPyRegistry.py with functions to handle reading / writing config files automatically to the scripts/bpydata/config dir. - Removing dir release/bpydata and its contents (moved earlier to release/scripts/bpydata/) - Bug #2379: made small changes to bevel_center's ui to fix a problem reported by Alexander Ewering (intrr): http://projects.blender.org/tracker/?func=detail&atid=125&aid=2379&group_id=9 BPython: - Thanks Campbell Barton for new functionality: Blender.Get() now can also return all the paths from the user prefs -> file paths win and there is a new function: Blender.sys.expandpath() to transform Blender paths (those starting with '//' and ending with '#') to absolute paths. - Added function Blender.ShowHelp(), to open the Scripts Help Browser with a given help page -- just a time saver for scripts. - Improved function Blender.Run() to also work with gui and file select scripts. - Found a (new?) crash related to NMesh.PutRaw when creating a new object while in edit mode. Leaving / entering edit mode fixes the problem, so a check for obj created, edit mode and leaving / re-entering it were added to the code for now (gdb didn't help much, no backtrace) - doc updates, including splitting intro page in two, with bpython related stuff (registering / documenting / configuring scripts and command line mode (thanks Chris Want for "use system variables to pass parameters to scripts" idea). - Registry: functions have been updated to support writing to / reading from disk, for the config editor -- only simple config data supported, for large amounts coders should write to a file themselves. This is done with a new parameter: Registry.GetKey(keyname, True) will also search for the key on the config dir, if not already loaded; equiv. for Registry.SetKey(keyname, dict, True). Data is only written to / read from disk when needed and only scripts already used (assuming they support this functionality) will have config data saved.
159 lines
4.4 KiB
Python
159 lines
4.4 KiB
Python
# Blender.sys module
|
|
|
|
"""
|
|
The Blender.sys submodule.
|
|
|
|
sys
|
|
===
|
|
|
|
B{New}: L{expandpath}.
|
|
|
|
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)
|
|
|
|
# what would basename(splitext(filename)[0]) print?
|
|
|
|
@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
|
|
"""
|
|
|
|
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.
|
|
"""
|
|
|
|
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)
|
|
"""
|
|
|
|
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
|
|
"""
|
|
|
|
def exists(path):
|
|
"""
|
|
Tell if the given pathname (file or dir) exists.
|
|
@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.
|
|
"""
|
|
|
|
def time ():
|
|
"""
|
|
Get the current time in seconds since a fixed value. Successive calls to
|
|
this function are guaranteed to return values greater than the previous call.
|
|
@rtype: float
|
|
@return: the elapsed time in seconds.
|
|
"""
|
|
|
|
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.
|
|
"""
|
|
|
|
def expandpath (path):
|
|
"""
|
|
Expand the given Blender 'path' into an absolute and valid path.
|
|
Internally, Blender recognizes two special character sequences in paths:
|
|
- '//' (used at the beginning): means base path -- the current .blend file's
|
|
dir;
|
|
- '#' (used at the end): means current frame number.
|
|
The expanded string can be passed to generic python functions that don't
|
|
understand Blender's internal relative paths.
|
|
@note: this function is also useful for obtaining the name of the image
|
|
that will be saved when rendered.
|
|
@note: if the passed string doesn't contain the special characters it is
|
|
returned unchanged.
|
|
@type path: string
|
|
@param path: a path name.
|
|
@rtype: string
|
|
@return: the expanded (if necessary) path.
|
|
"""
|