[Bf-python] Proposed BPyAPI Additions.

Campbell Barton cbarton at metavr.com
Sat Sep 2 02:03:49 CEST 2006


Willain, Im happy with the last option
adds "from Blender import *"

Only issue is that Blender module functions should be imported -
Blender.Get('currframe')

would not be
Get('currframe')
 
Having constants in the module  directly is good when all the names are 
uppercase too. - Lamp.SUN

# At the risk of being pedantic
scene.add(Lamp(name, Lamp.SUN))
# should be?
scene.objects.new(Lamp(name, Lamp.SUN))


The difference between .add and .new in the proposal is
scn.objects.add(ob) # Adds an object to the scene
ob= scn.objects.new(data)  # creates an object from any obdata and 
returns that object

Can be changed of course, but the change needs to go into some details- 
maybe add an alternative in the wiki discussions, or post here on the ML.


Willian Padovani Germano wrote:
> 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?
>


-- 
Campbell J Barton

133 Hope Street
Geelong West, Victoria 3218 Australia

URL:    http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241



More information about the Bf-python mailing list