提供: wiki
< Dev:2.4‎ | Source‎ | Python‎ | API
移動先: 案内検索

Scene Refactor Proposal

This page proposes additions to the existing BPY API, as discussed by Willain and Campbell (31/08/2006) Variable names may change, existing functionality may eventually be depricated (after 2.43 release) and only these functions supported. - for now we will not break compatibility.

The Super Iterator

This came up when dealing with objects and listbases. scn.getChildren() scn.Link() and scn.Unlink() is not an ideal way to deal with objects. A thin wrapper for listbases is very efficient and fits nicely into the python API as a set() like pyType.

a new iterator has been added to the scene called objects. This allows you do iterate through the scenes objects and has functions for adding and removing.

Current functionality

  for ob in scn.objects: print
  scn.objects.add(my_object) # Add an existing object, like
  scn.objects.remove(my_object) # Remove an existing object, like scn.Unlink()
  ob= # make a new object from obdata, replaces the existing 2-3 step method and avoids objects having no data.

Possible functionaly

  ob= #get the active object, like ob= scn.getActiveObject()
  ob= scn.objects['MyObject'] # get an object from the scene by name, must not be confused with Object.Get('MyObject')
  scn.objects.remove('myObject') # remove the object by name rather then getting the obdata first.
  scn.objects.extend([ob1, ob2, ob3]) # add objects at once.

The advantage of this is that it separates all objects into a part of scene and makes the scenes functions less polluted.

Sub iterators

  scn.objects.selected # iterator that iterates over selected objects, inherits most functionality from scn.objects
  scn.objects.context # iterator that iterates over visible selected objects.

Other Iterators

2 new iterator that will be added

  • Blender.scenes # will be "scenes" where "from Blender import *" is used.
  • scn.scriptlinks

Proposed functionality

  active= # consistent with
  for scn in scenes: print

Other iterators exist- group.objects, object.modifiers, mesh.verts, - we will try and make these iterators be consistent where possible.

More could be added but for now this is what we will add in the short term.

Data Access

A problem with the existing API is that data access is mixed in. A new module will be added - name is undecieded... but for now we'll call it "Data"

This would eventuallly replace the Get() functions

  obs= Objects.Get()

would be

  obs= Data.objects

we would have access to .meshes, .worlds etc, These would be thin wrappers around G.main listbases.

Eventually .add() .remove() etc could be added also where applicable.

It may be that this is added as a part of Blender.Library