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

Packing external images

If we use image files for our add-on, we can create a folder in the structured_addon directory and name it pictures. Since we are going to write a module for loading icons, this folder can contain a collection of image files.

In the ch6\addons\structured_addon\pictures folder from the examples, we have pack_64.png, a clipart representing a package, and smile_64.png, the smiley face from the previous chapter:

Figure 6.5: The pictures used for this add-on are stored in a folder

Figure 6.5: The pictures used for this add-on are stored in a folder

Once all our images are in this folder, we can write the code to load them.

Writing an icon library

In Chapter 5, we wrote a function that loads a specific image file from disk. That worked great. Now that we are loading two icons, we can just use the same routine twice.

But now that we have an entire module for loading images, we can write a more sophisticated solution that works for any number of icons since it doesn’t rely on hardcoded...