Module Scene :: Class Scene
[hide private]
[frames] | no frames]

Class Scene

source code

The Scene object

This object gives access to Scene data in Blender.

Instance Methods [hide private]
string
getName()
Get the name of this Scene.
source code
 
setName(name)
Set the name of this Scene.
source code
list of integers
getLayers()
Get the layers set for this Scene.
source code
 
setLayers(layers)
Set the visible layers for this scene.
source code
Scene
copy(duplicate_objects=1)
Make a copy of this Scene.
source code
 
makeCurrent()
Make this Scene the currently active one in Blender.
source code
 
update(full=0)
Update this Scene in Blender.
source code
RenderData
getRenderingContext()
Get the rendering context for this scene, see Render.
source code
Blender Radiosity
getRadiosityContext()
Get the radiosity context for this scene, see Radio.
source code
list of Blender Objects
getChildren()
Get all objects linked to this Scene.
source code
Blender Object or None
getActiveObject()
Get this scene's active object.
source code
Blender Object
getCurrentCamera()
Get the currently active Camera for this Scene.
source code
 
setCurrentCamera(camera)
Set the currently active Camera in this Scene.
source code
 
link(object)
Link an Object to this Scene.
source code
boolean
unlink(object)
Unlink an Object from this Scene.
source code
list
getScriptLinks(event)
Get a list with this Scene's script links of type 'event'.
source code
 
clearScriptLinks(links=None)
Delete script links from this Scene.
source code
 
addScriptLink(text, event)
Add a new script link to this Scene.
source code
bool
play(mode=0, win='<VIEW3D>')
Play a realtime animation.
source code
Instance Variables [hide private]
integer (bitmask) Layers
The Scene layers (check also the easier to use layers).
Camera or None camera
The active camera for this scene (can be set)
Vector (wrapped) cursor
the 3d cursor location for this scene.
bool fakeUser
When set to True, this datablock wont be removed, even if nothing is using it.
OpenEXR's half float option halfFloat
boolean
list of integers layers
The Scene layers (check also Layers).
string or None lib
path to the blend file this datablock is stored in (readonly).
string name
unique name within each blend file.
Skip rendering existing image files noOverwrite
boolean
sequence of objects objects
The scene's objects.
OpenEXR's save preview option preview
boolean
IDGroup properties
Returns an IDGroup reference to this datablocks's ID Properties.
RenderData radiosity
The scenes radiosity settings.
RenderData render
The scenes render settings.
bool tag
A temporary tag that to flag data as being used within a loop.
Timeline timeline
The timeline for this scene, named markers are stored here.
enable creating empty image files while they are rendered. touch
boolean
int users
The number of users this datablock has.
World or None world
The world that this scene uses (if any)
OpenEXR's save zbuf option zbuf
boolean
Method Details [hide private]

setName(name)

source code 
Set the name of this Scene.
Parameters:
  • name (string) - The new name.

getLayers()

source code 
Get the layers set for this Scene.
Returns: list of integers
a list where each number means the layer with that number is set.

setLayers(layers)

source code 
Set the visible layers for this scene.
Parameters:
  • layers (list of integers) - a list of integers in the range [1, 20], where each available index makes the layer with that number visible.

Note: if this Scene is the current one, the 3D View layers are also updated, but the screen needs to be redrawn (at least 3D Views and Buttons windows) for the changes to be seen.

copy(duplicate_objects=1)

source code 
Make a copy of this Scene.
Parameters:
  • duplicate_objects (int) - Defines how the Scene children are duplicated:
    • 0: Link Objects;
    • 1: Link Object Data;
    • 2: Full copy.
Returns: Scene
The copied Blender Scene.

update(full=0)

source code 
Update this Scene in Blender.
Parameters:
  • full (int) - A bool to control the level of updating:
    • 0: sort the base list of objects.
    • 1: sort and also regroup, do ipos, keys, script links, etc.

Warning: When in doubt, try with full = 0 first, since it is faster. The "full" update is a recent addition to this method.

getRenderingContext()

source code 
Get the rendering context for this scene, see Render.
Returns: RenderData
the render data object for this scene.

getRadiosityContext()

source code 
Get the radiosity context for this scene, see Radio.
Returns: Blender Radiosity
the radiosity object for this scene.

Note: only the current scene can return a radiosity context.

getChildren()

source code 
Get all objects linked to this Scene. (deprecated). Note: new scripts should use the objects attribute instead. In cases where a list is required use list(scn.objects).
Returns: list of Blender Objects
A list with all Blender Objects linked to this Scene.

Note: Object.Get will return all objects currently in Blender, which means all objects from all available scenes. In most cases (exporter scripts, for example), it's probably better to use this scene.GetChildren instead, since it will only access objects from this particular scene.

Warning: Depricated! use scene.objects instead.

getActiveObject()

source code 
Get this scene's active object.
Returns: Blender Object or None
the active object or None if not available.

Note: the active object, if selected, can also be retrieved with Object.GetSelected -- it is the first item in the returned list. But even when no object is selected in Blender, there can be an active one (if the user enters editmode, for example, this is the object that should become available for edition). So what makes this scene method different from Object.GetSelected()[0] is that it can return the active object even when no objects are selected.

Warning: Depricated! use scene.objects.active instead.

getCurrentCamera()

source code 
Get the currently active Camera for this Scene.
Returns: Blender Object
The currently active Camera object.

Note: The active camera can be any object type, not just a camera object.

setCurrentCamera(camera)

source code 
Set the currently active Camera in this Scene.
Parameters:
  • camera (Blender Camera) - The new active Camera.

link(object)

source code 
Link an Object to this Scene.
Parameters:
  • object (Blender Object) - A Blender Object.

unlink(object)

source code 
Unlink an Object from this Scene.
Parameters:
  • object (Blender Object) - A Blender Object.
Returns: boolean
true if object was found in the scene.

getScriptLinks(event)

source code 
Get a list with this Scene's script links of type 'event'.
Parameters:
  • event (string) - "FrameChanged", "OnLoad", "OnSave", "Redraw" or "Render".
Returns: list
a list with Blender Text names (the script links of the given 'event' type) or None if there are no script links at all.

clearScriptLinks(links=None)

source code 
Delete script links from this Scene. If no list is specified, all script links are deleted.
Parameters:
  • links (list of strings) - None (default) or a list of Blender Text names.

addScriptLink(text, event)

source code 

Add a new script link to this Scene.

Using OpenGL functions within a scene ScriptLink will draw graphics over the 3D view. There is an issue with the zoom of the floating panels also scaling graphics drawn by your scriptlink. This makes matching OpenGL graphics to mouse location impossible. Make sure that you use floating point for operations that you would usually use int functions for: glRasterPos2f rather then glRasterPos2i.

The following example shows how you can use the OpenGL model view matrix to obtain the scale value.

Example:
       from Blender import BGL
       view_matrix = BGL.Buffer(BGL.GL_FLOAT, 16)
       BGL.glGetFloatv(BGL.GL_MODELVIEW_MATRIX, view_matrix)
       gl_scale = 1/viewMatrix[0]
       
       # Now that we have the scale we can draw to the correct scale.
       BGL.glRect2f(10*gl_scale, 10*gl_scale, 110*gl_scale, 110*gl_scale)
Parameters:
  • text (string) - the name of an existing Blender Text.
  • event (string) - "FrameChanged", "OnLoad", "OnSave", "Redraw" or "Render".

play(mode=0, win='<VIEW3D>')

source code 
Play a realtime animation. This is the "Play Back Animation" function in Blender, different from playing a sequence of rendered images (for that check Render.RenderData.play).
Parameters:
  • mode (int) - controls playing:
    • 0: keep playing in the biggest 'win' window;
    • 1: keep playing in all 'win', VIEW3D and SEQ windows;
    • 2: play once in the biggest VIEW3D;
    • 3: play once in all 'win', VIEW3D and SEQ windows.
  • win (int) - window type, see Window.Types. Only some of them are meaningful here: VIEW3D, SEQ, IPO, ACTION, NLA, SOUND. But the others are also accepted, since this function can be used simply as an interruptible timer. If 'win' is not visible or invalid, VIEW3D is tried, then any bigger visible window.
Returns: bool
0 on normal exit or 1 when play back is canceled by user input.

Instance Variable Details [hide private]

Layers

The Scene layers (check also the easier to use layers). This value is a bitmask with at least one position set for the 20 possible layers starting from the low order bit. The easiest way to deal with these values in in hexadecimal notation. Example:
       scene.Layers = 0x04 # sets layer 3 ( bit pattern 0100 )
       scene.Layers |= 0x01
       print scene.Layers # will print: 5 ( meaning bit pattern 0101)
After setting the Layers value, the interface (at least the 3d View and the Buttons window) needs to be redrawn to show the changes.
Type:
integer (bitmask)

fakeUser

When set to True, this datablock wont be removed, even if nothing is using it. All data has this disabled by default except for Actions.
Type:
bool

layers

The Scene layers (check also Layers). This attribute accepts and returns a list of integer values in the range [1, 20]. Example:
       scene.layers = [3] # set layer 3
       scene.layers = scene.layers.append(1)
       print scene.layers # will print: [1, 3]
Type:
list of integers

lib

path to the blend file this datablock is stored in (readonly).

lib will be None unless you are using external blend files with (File, Append/Link)

Note: the path may be relative, to get the full path use Blender.sys.expandpath
Type:
string or None

name

unique name within each blend file.

The name is case sensitive and 21 characters maximum length.

Note: a blend file may have naming collisions when external library data is used, be sure to check the value of lib.

Note: Setting a value longer then 21 characters will be shortened
Type:
string

objects

The scene's objects. The sequence supports the methods .link(ob), .unlink(ob), and .new(obdata), and can be iterated over.
Type:
sequence of objects

radiosity

The scenes radiosity settings. (read only)
Type:
RenderData

render

The scenes render settings. (read only)
Type:
RenderData

tag

A temporary tag that to flag data as being used within a loop. always set all tags to True or False before using since blender uses this flag for its own internal operations.
Type:
bool

timeline

The timeline for this scene, named markers are stored here. (read only)
Type:
Timeline

users

The number of users this datablock has. (readonly) Zero user datablocks are de-allocated after reloading and saving.
Type:
int