Blender 3D: Noob to Pro/Python Scripting/Tutorial (Blender 2.4.9)
The original tutorial that this text stems from can be found at Blender 3D: Noob to Pro/Advanced Tutorials/Python Scripting/Export scripts.
Some prerequisites:
- Familiarity with Blender.
- Fundamental understanding of python. (read the Python manual once, do the tutorials)
- Most importantly: a desire to learn. Understanding of the material will increase as we progress, along with complexity
To accompany this tutorial, bookmark: http://www.blender.org/documentation/248PythonDoc. 248PythonDoc covers all exposed methods that we can access via Python. It will benefit you to have a browse through it once at your own pace, before going further, even if little of it makes sense.
NOTE: I use Windows so some info here may be different on Mac OS X and Linux.
Change a windowtype to Scripts, then click Scripts → System → Interactive Python Console. This will display a console not unlike the IDLE that comes with Python distributions. The window will display some useful information, read it once. The last few lines will read:
import bpy import Blender from Blender import *
This has imported modules and methods so that you can draw, query and manipulate scene objects.
Let's look at some existing scripts, to do so we can change the windowtype to Text Editor and open one of the scripts in the .blender/scripts folder. Any of the scripts that appear in the scripts menu of the Interactive Python Console will start off with some standard bookkeeping like the following lines:
#!BPY """ Registration info for Blender menus: Name: 'Name as it appears in the menu' Blender: 249b Group: 'Mesh' Tooltip: 'Change this template text tooltip, else it defaults to scriptname.py' """ __author__ = "FooName" __url__ = ("blender", "www.j00rURL.com") __version__ = "1.0" __bpydoc__ = """\ This is where you document the general workings of the script, keep it short but informative. """