Graphics Reference
In-Depth Information
Chapter 13
Python Scripting for Blender
In this chapter, you'll begin writing Python scripts for Blender. This requires becoming familiar with Blender's
Python coding environment and the Blender-Python API. This chapter teaches you how to place objects in
Blender's 3D space and manipulate their associated values in your script. You'll also learn how the Blender-
Python interface construction tools work, which will enable you to create interactive scripts and tools. The goal
is to show you not only how to accomplish the specific tasks in this chapter's tutorials but also how to mine the
sometimes-daunting API specifications for the information you need to accomplish your own goals.
In this chapter, you will learn to
• Edit and run interactive scripts in Blender
• Become familiar with the Blender-Python API
• Design your own GUI with an interactive script
Editing and Running Scripts in Blender
With the recode of Blender's interface and API prior to Blender 2.5, the Python API became more tightly integ-
ratedwithBlender'sinternaldatastructuringsystem.ThismeantthatmoreofBlender'scoreC/C++functionality
could be accessed and controlled by means of Blender scripts. Indeed, although you may not see it at first blush,
a lot of what you are doing already uses Python as glue to connect the interface to the underlying functionality.
Don't believe me? Try going into your Blender application directory and deleting the scripts directory (be
sure to back it up first). When you run Blender after doing that, you'll see it start up as normal, and then you'll
see the default screen look something like Figure 13-1 . It looks familiar, but it's certainly not the Blender you've
come to know and love! As you can see, much of Blender's interface is already written in the form of Python
scripts. That's why Python lets you create your own custom controls that integrate perfectly into the Blender in-
terface. It's also why once you know what you're doing with Python, you'll be able to root around the scripts
directory yourself and customize just about anything.
Now that you've looked at the basics of the Python programming language, you're ready to begin working
with the Blender-Python API and create scripts that access your Blender 3D and workspace data.
 
Search WWH ::




Custom Search