[Bf-python] __blender__ constant

Thomas Bleicher tbleicher at arcor.de
Fri Dec 30 22:36:04 CET 2005


On 14.12.2005, at 00:37, dunk wrote:

> try:
> 	__blender__
> except NameError:
> 	# no blender

Where you have placed "# no blender" you'd have to react and
(in most cases) just inform the user and exit. When you use
"try: import" you can import a substitute for your script right
when the exception occures.

Example:

I have created a PyOpenGL wrapper to simulate Blenders "BGL" and
"Draw" module (and a few others but incomplete). Now all I have
to do is to start the scripts with

try:
     import Blender
     from Blender import Draw, BGL
except ImportError:
     import BlenderDummy as Blender
     from BlenderDummy import Draw, BGL

and the whole script works as well inside Blender as in plain OpenGL.
There are a few exceptions where I had to create abstractions inside
my script code (like the FileSelector) and now I have to use these
instead of the Blender original. But there are only a few and the
difference is small.

Thomas



More information about the Bf-python mailing list