[Bf-python] Proposed BPyAPI Additions.

Willian Padovani Germano wgermano at superig.com.br
Sat Sep 2 03:09:49 CEST 2006


Hi again,

Nothing original here, it's an old natural idea: let's automatically 
import and add to the main dict a few modules when we initialize the 
Python interpreter. We already do that for the pydrivers and pybutton 
global dict, it's trivial to move it to the main interpreter one.

The obvious choice is the top Blender module. No need for almost all 
scripts to start with "import Blender"...

With this change the script:

import Blender
scene = Blender.Scene.GetCurrent()
print scene.name

can become:

scene = Scene.GetCurrent()
print scene.name

or, with the alternative way:

scene = scenes.active
print scene.name

# or simply

print scenes.active.name

Other choices besides the Blender module might be: math, 
Blender.Mathutils, Blender.Noise, ??

Following Theeth's suggestion of having the constants in the modules 
directly, this:

import Blender
from Blender import Object, Lamp, Scene
lamp = Object.New(name, Lamp.Types.Sun)
scene = Scene.GetCurrent()
scene.link(lamp)

# could be:

lamp = Object.New(name, Lamp.SUN)
scene = Scene.GetCurrent()
scene.link(lamp)

# or:

scene = scenes.active
scene.add(Lamp(name, Lamp.SUN))

# or whatever we add as alternative

Advantages:

- Only have to import these basic modules once, at startup.
- Less typing, more readable scripts.
- Existing scripts won't break.

Everybody ok with this?

-- 
Willian



More information about the Bf-python mailing list