Blender Documentation Volume II - Reference Guide: Last modified July 08 2004 S68
<<< Previous | Buttons Reference | Next >>>

# Script Context

## ScriptLinks - Linking scripts to Blender

Python scripts can be attached to DataBlocks with the ScriptButtons window, and assigned events that define when they should be called. Just one Panel, `Scriptlinks` is present.

ScriptLinks can be added for the following DataBlocks

- Objects - Available when an Object is active;

- Cameras - Available when the active Object is a Camera;

- Lamps - Available when the active Object is a Lamp;

- Materials - Available when the active Object has a Material;

- Worlds - Available when the current scene contains a World;

These can be selected with the top row of Toggle Buttons in the Panel. Please note that only the Buttons which are applicable are present.

Selecting one of the Toggle Buttons brings up the `Selected Scriptlink` Buttons group in the middle of the Panel.

DataBlocks can have an arbitrary number of ScriptLinks attached to them - additional links can be added and deleted with the `New` and `Del` buttons, similar to Material Indices. Scripts are executed in order, beginning with the script linked at index one.

When you have at least one Scriptlink the Event type Menu and link buttons are displayed. The link button should be filled in with the name of the Text Object containing the script to be executed. The Event type indicates at what point the script will be triggered:

- `FrameChanged` - This event is executed every time the user changes frame, and during rendering and animation playback. To provide more user interaction this script is also executed continuously during editing for Objects.

- `Redraw` - This event is executed every time Blender redraws its Windows.

Scripts that are executed because of events being triggered receive additional input by objects in the Blender module.

- The Blender.bylink object is set to True to indicate that the script has been called by a ScriptLink (as opposed to the user pressing Alt-P in the Text window).

- The Blender.link object is set to contain the DataBlock which referenced the script, this may be a Material, Lamp, Object, etc.

- The Blender.event object is set to the name of the event which triggered the ScriptLink execution. This allows one script to be used to process different event types.

### Scene ScriptLinks

The ScriptLink buttons for Scenes are always available at the bottom of the `Scriptlink` Panel, and function exactly in the manner described above, but on a scene wide context. Events available for SceneScriptLinks are:

- FrameChanged - This event is executed every time the user changes frame, and during rendering and animation playback.

- OnLoad - This event is executed whenever the Scene is loaded, ie. when the file is initially loaded, or when the user switches to the current scene.

- Redraw - This event is executed every time Blender redraws its Windows.

<<< Previous | Home | Next >>>
Logic Context | Up | Shading Context