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 operator flow

We dealt with operators since Chapter 3, and we learned how their poll method checks whether the operator can be executed, while execute performs the operation and exits.

Then in Chapter 4, we added editable parameters to the Elevator operator, thanks to the 'REGISTER' and 'UNDO' options.

We also learned about the clever trick to change a result in real time when a user changes a parameter – Blender secretly undoes the last operation and performs it again with the new options, hence the need for 'UNDO'.

That became more evident in Chapter 7, when we learned how using Edit | Adjust Last Operation from the menu bar changes the result of the last operation.

While those solutions allow us to get input parameters with ease, they don’t give access to the actual input events, such as the pressure of a key or the movement of a mouse.

That would require a listener – that is, code that waits for...