Book Image

Python Scripting in Blender

By : Paolo Acampora
5 (1)
Book Image

Python Scripting in Blender

5 (1)
By: Paolo Acampora

Overview of this book

Blender, a powerful open source 3D software, can be extended and powered up using the Python programming language. This book teaches you how to automate laborious operations using scripts, and expand the set of available commands, graphic interfaces, tools, and event responses, which will enable you to add custom features to meet your needs and bring your creative ideas to life. The book begins by covering essential Python concepts and showing you how to create a basic add-on. You’ll then gain a solid understanding of the entities that affect the look of Blender’s objects such as modifiers, constraints, and materials. As you advance, you’ll get to grips with the animation system in Blender and learn how to set up its behavior using Python. The examples, tools, patterns, and best practices present throughout the book will familiarize you with the Python API and build your knowledge base, along with enabling you to produce valuable code that empowers the users and is ready for publishing or production. By the end of this book, you’ll be able to successfully design add-ons that integrate seamlessly with the software and its ecosystem.
Table of Contents (19 chapters)
1
Part 1: Introduction to Python
7
Part 2: Interactive Tools and Animation
13
Part 3: Delivering Output

Understanding the user context

The current state of interaction, the current scene, and the selection are available via bpy.context. Since it depends on the user actions, bpy.context is read-only; that is, it cannot be changed directly. Anyway, we can affect the state of the current activity via Python. Rather than changing the attributes of bpy.context, we must look for the selection and activity properties of Blender’s objects, layers, and scenes.

Active scene

A .blend file, or an unsaved session for that matter, can contain more than one scene. That differs from the standard in 3D packages, where a saved file is equivalent to one scene. If more scenes are available, they can be selected from the list menu at the top right of Blender’s header.

Each scene can contain any of the objects from bpy.data.objects, and one object can belong to more than one scene. Changes made to an object in one scene retained in the others.

We have seen how to create new objects...