Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Python Scripting in Blender
Python Scripting in Blender

Python Scripting in Blender: Extend the power of Blender using Python to create objects, animations, and effective add-ons

By Paolo Acampora
€33.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
Book Jun 2023 360 pages 1st Edition
eBook
€26.99 €17.99
Print
€33.99
Subscription
€14.99 Monthly
eBook
€26.99 €17.99
Print
€33.99
Subscription
€14.99 Monthly

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Black & white paperback book shipped to your address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Jun 9, 2023
Length 360 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781803234229
Vendor :
Blender Foundation
Category :
Table of content icon View table of contents Preview book icon Preview Book

Python Scripting in Blender

Python’s Integration with Blender

Blender accepts code instructions in the same way as it interacts: via a graphical user interface.. That allows artists and studios to implement their own features and automation.

Python, a highly extensible programming language with low barriers to entry, is widely used in computer graphics.

Though Blender’s core is written in C and C++, menus and graphic elements use Python. That allows custom and factory functionalities to share the same look and feel.

In this chapter, we’ll learn how to run Python commands in Blender and where to look for their outcome. We will also see where a history of past instructions is found and how to use that to our advantage. Lastly, we will introduce a code editor and a version control system and see how they help make our work easier.

By the end of this chapter, you will understand how a programmer works and why it is not so different from using software in the first place.

In this chapter, we will cover the following main topics:

  • The scripting workspace
  • Python execution
  • Version control

Technical requirements

Besides Blender 3.3+ or in this case, Blender 3.3 (https://www.blender.org/download/lts/3-3), you will require the following free tools:

You are encouraged to write your own code; the examples for this chapter can be found at the following URL: https://github.com/PacktPublishing/Python-Scripting-in-Blender/tree/main/ch1.

Since it is a free, open source software, there are plenty of ways to install Blender. We are going to look at the most common install solutions.

Installing Blender

The procedure for installing Blender varies with the operating system. Like most applications, installers for Microsoft Windows and Apple macOS are provided. Also, portable versions, such as archives that can be uncompressed and executed everywhere in the system, are available for Linux and Windows.

The version of Blender used in this book, 3.3, might differ from other versions already installed on the system. In that case, we can install different versions of Blender on the same machine.

Installing Blender on Windows

There are more ways to install a program on Microsoft Windows: Windows Installer, Microsoft Store, and using a portable archive. While most application publishers choose one of those options, all of them are available for Blender.

Installing multiple versions via Windows Installer

The most common way to install Blender on Windows is to download Windows Installer from Blender’s download page. Executing the downloaded .msi file installs Blender. Before Blender 3.4, only one of the multiple installed versions was available in the Start menu.

If that is the case for you, the other versions can be accessed by navigating to the Program Files folder, usually C:\Program Files\Blender Foundation, using Windows Explorer.

We can execute blender.exe directly from the Blender 3.3 folder or use right-click > New > Shortcut in Windows Explorer and create a shortcut to it:

Figure 1.1: Multiple versions of Blender in Program Files

Figure 1.1: Multiple versions of Blender in Program Files

Alternatively, since version 3.3 is a Long-term Support version, it is also available in the Microsoft Store.

Installing Blender from the Microsoft Store

The download page of Blender 3.3 provides a link to the Microsoft Store installer. Alternatively, we can start Microsoft Store from the Start menu and look up blender in the top bar. Once we get to the Blender page, we make sure that it’s published by Blender Foundation and click the Get button:

Figure 1.2: Installing Blender from the Microsoft Store

Figure 1.2: Installing Blender from the Microsoft Store

That will add a Blender 3.3 entry in the Start menu:

Figure 1.3: Multiple versions in the Start menu

Figure 1.3: Multiple versions in the Start menu

Microsoft Store gives the advantage of always adding a shortcut for the installed version. If, for some reason, Microsoft Store is not an option, we can download a portable archive.

Downloading a portable archive

To avoid any application packaging, we can download a Windows portable .zip file, or a Linux .tar.xz archive.

Portable versions can be used from any location of the system, even removable drives. We only need to extract the archive in a directory of choice via right-clicking -> Extract in the file manager and then executing the blender.exe or blender executable in the unpacked folder.

Installing multiple versions on macOS

We can download the .dmg packages for Apple Intel or Apple Silicon computers. Once downloaded, double-clicking the file will open the installer window. If another version of Blender is already present in the system, a prompt dialog will ask whether we want to keep both or replace the installed version with the new one.

Selecting Keep Both will install the new version as Blender 2. The digit depends on the installation order and doesn’t reflect the actual version of Blender. We can rename it Blender 3.3 using right-click -> Rename on the Application entry in the file manager:

Figure 1.4: Installing an additional version of Blender on macOS

Figure 1.4: Installing an additional version of Blender on macOS

There are many other ways to install Blender: a link to stores such as Steam (Windows, macOS, or Linux) or Snapcraft (Linux only) is provided on the download page, not to mention the package manager of Linux distribution (apt on Ubuntu, yum on CentOS, and so on). It is worth mentioning that it is possible to build Blender from the source code, but that’s an advanced topic beyond the scope of this book.

While this book sticks to version 3.3, the examples should work on future releases of the 3.x series with minor corrections at worst.

A future major release, such as Blender 4 or 5, is almost guaranteed to break compatibility with past scripts. Still, the knowledge from this book about best practices and thought patterns will stand the test of time.

Now that we have installed Blender on our system, we can dive into its scripting capabilities.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Discover ready-to-go scripts that provide a clear solution to your problems
  • Find out how to automate repetitive tasks in an efficient way
  • Extend Blender’s actions and user interface with your code

Description

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.

What you will learn

Understand the principles of 3D and programming, and learn how they operate in Blender Build engaging and navigation-friendly user interfaces that integrate with the native look and feel Respect coding guidelines and deliver readable and compliant code without the loss of originality Package your extensions into a complete add-on, ready for installation and distribution Create interactive tools with a direct response to the user’s action Code comfortably and safely using version control

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Black & white paperback book shipped to your address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Jun 9, 2023
Length 360 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781803234229
Vendor :
Blender Foundation
Category :

Table of Contents

19 Chapters
Preface Chevron down icon Chevron up icon
1. Part 1: Introduction to Python Chevron down icon Chevron up icon
2. Chapter 1: Python’s Integration with Blender Chevron down icon Chevron up icon
3. Chapter 2: Python Entities and API Chevron down icon Chevron up icon
4. Chapter 3: Creating Your Add-Ons Chevron down icon Chevron up icon
5. Chapter 4: Exploring Object Transformations Chevron down icon Chevron up icon
6. Chapter 5: Designing Graphical Interfaces Chevron down icon Chevron up icon
7. Part 2: Interactive Tools and Animation Chevron down icon Chevron up icon
8. Chapter 6: Structuring Our Code and Add-Ons Chevron down icon Chevron up icon
9. Chapter 7: The Animation System Chevron down icon Chevron up icon
10. Chapter 8: Animation Modifiers Chevron down icon Chevron up icon
11. Chapter 9: Animation Drivers Chevron down icon Chevron up icon
12. Chapter 10: Advanced and Modal Operators Chevron down icon Chevron up icon
13. Part 3: Delivering Output Chevron down icon Chevron up icon
14. Chapter 11: Object Modifiers Chevron down icon Chevron up icon
15. Chapter 12: Rendering and Shaders Chevron down icon Chevron up icon
16. Index Chevron down icon Chevron up icon
17. Other Books You May Enjoy Chevron down icon Chevron up icon
Appendix Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


N/A Nov 27, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A little hard to follow when typing in code. It would be nice to have the complete code at the end of the book. What I type in is rarely what is shown in the github examples. Could be a little clearer as to where code changes are needed in a project. I am not a programmer so the problems could just be me, I think the book is very good.
Feefo Verified review Feefo image
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela