Chapter 12
Python Scripts and Add-Ons
Python is a high-level, object-oriented scripting language. Powerful and relatively easy to learn, it is an obvious choice as a standard scripting language for an open source 3D application such as Blender. With Python scripts, you can automate a great deal of interaction with your 3D objects and scenes and add functionality without needing to touch actual Blender code. It is also a good way to try new functionality that can later be incorporated into Blender’s C/C++ source.
With the changes in Blender 2.5, the Python API for developers has been completely overhauled, and a new interface for extending functionality in a totally seamless way through add-ons has been added. In this chapter, you’ll take a look at the add-ons system and see some of the available add-ons. The rest of this chapter will give a brief overview of how Python works in Blender and point you at resources to learn more. People with some programming experience will find Python scripting for Blender relatively easy to pick up.
- Using Add-Ons
- The Blender Python API
- Learning More about Blender Python Scripting
. Along the left of this panel is a list of add-on categories. Clicking one of these buttons will limit the listing to that category. In the figure, All is selected, giving a scrollable list of all the available add-ons.
You can expand each entry of the list by clicking the arrow icon at the left of the entry to see a description of the add-on’s functionality. You activate the add-on by clicking the check box at the right of the entry. When you do this, the add-on functionality is immediately added to Blender.
If that’s all you do, the add-on functionality will disappear the next time you restart Blender. If you want the functionality to persist for future sessions, click the Save As Default button at the bottom of the User Preferences window.
The Install Add-On button enables you to use third-party add-ons that you download from other sites or create yourself.
Some Useful Add-Ons
The best overview of the add-on functionality available is the Add-Ons panel. The add-ons are clearly organized into meaningful categories and are named in a way that gives strong clues to their functionality. Expanding the description should give you all the information you need to find out what the add-on does. I strongly suggest browsing this list on your own to see the many interesting and useful features available.
The 3D View category includes various functionality connected to viewing the 3D space and organizing objects within the space. Alignment, navigation, and visualization tools can be accessed here, as well as some legacy menus used in previous Blender versions that have been discontinued or reorganized in the 2.5 interface. shows the functionality of the Measure Panel add-on, which enables the display of the exact distance between objects for precision placement.
The Add Curve and Add Mesh categories provide additional object primitives for Curve and Mesh objects. The Curvaceous Galore add-on shown in , for example, enables you to add ready-made parametric curve primitives of stars, cogwheels, flowers, splatter patterns, and other shapes. The ANT Landscape add-on for meshes enables you to add automatically generated landscape models, as shown in .
The Animation category includes an alternate method to create corrective shape keys and the Rotobezier add-on, which enables easy animation of curve shapes (this is particularly useful when rotoscoping for compositing but has many other possible uses as well).
The Import/Export category extends Blender’s standard import and export functionality, enabling a wider variety of file types to be read from and written to.
The Mesh category extends mesh datablock-related and mesh modeling–related functionality.
The Object category includes miscellaneous functionality that deals in some way with 3D objects at the object level. This category includes the Cloud Generator add-on for creating clouds like the one shown in .
The other categories include Render, Rigging, System, and Text, all of which currently contain only one or two add-ons each. The Rigify add-on in the Rigging category should be familiar to you. You learned about it in Chapter 4.
. There is also an excellent thread in the Blender Artists forum at . At the time of this writing, the API remains somewhat subject to change, and it is beyond the scope of this book to give an in-depth introduction to Python scripting. The official web documentation is an excellent start if you want to try your hand at scripting.
An even closer-to-home reference for the Blender Python API is Blender. You may already have noticed that the mouseover tooltips display a line of Blender code for most interface elements in Blender, as shown in . Also, if you pull down the Info bar window at the top of the default screen configuration to display its contents, you will see that it prints the Python call for every operation you do on the screen, as shown in . If you want to know the Python call to rotate an object, simply rotate the object and watch what gets output to that window.
.
However you decide to get started, you won’t need anything other than Blender 2.5 to do so. A great new development in Blender 2.5 is the addition of a fully functional built-in Python interactive command-line interface, shown in . Many introductory Python tutorials assume that you are working in such a command-line environment. In the past, you would have needed a separate development environment outside of Blender to work in this way. Now all you need is right there.
Once you have a handle on Python, you will be able to create your own extended functionality for Blender. The possibilities really are endless, so I hope that this very brief overview has piqued your interest.
Part III of this book takes a look at how Blender has been used in large-scale projects, requiring the reuse and sharing of 3D data. Looking at how the Sintel and Plumiferos teams handled these tasks will yield even more insight into how to use Blender’s tools to create first-rate animation projects.