Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Scripting in Blender

You're reading from   Python Scripting in Blender Extend the power of Blender using Python to create objects, animations, and effective add-ons

Arrow left icon
Product type Paperback
Published in Jun 2023
Publisher Packt
ISBN-13 9781803234229
Length 360 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Paolo Acampora Paolo Acampora
Author Profile Icon Paolo Acampora
Paolo Acampora
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

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

External editor – Visual Studio Code

Visual Studio Code (VS Code), is a fast, multiplatform, free editor from Microsoft, available for Windows, macOS, and Linux. Using an external editor makes our code independent from a session of Blender. Also, a programmer text editor offers many utilities besides syntax highlighting.

VS Code 1.66 is used in this book. It is a fast, lightweight editor available for most platforms, but there are plenty of alternatives – most notably, the following:

  • Notepad++: This is a fast but powerful editor for Windows, available at https://notepad-plus-plus.org.
  • PyCharm: This is a Python integrated development environment (IDE) by JetBrains. A free community version can be found at https://www.jetbrains.com/pycharm.
  • LightTable: This is an interesting open source editor, available at http://lighttable.com.
  • Sublime: This is a commercial text editor, found at https://www.sublimetext.com.

Most Linux distributions come with at least one decent, ready-to-use, text editor. We encourage you to experiment and find the text editor of your choice.

In this section, we will set up VS Code for Python scripting.

Pick the right studio!

VS Code and Visual Studio have a similar name but are two different products from Microsoft. While VS Code is a programmer text editor, Visual Studio is a full development environment for advanced languages such as C++. While C++ projects may require a specific version of the building environment, it is safe to use any version of VS Code as long as Python is a supported language.

Loading our scripts folder

We can load the folder that contains our script files using the Open Folder… entry from the File menu. The editor will display the folder content on the first tab of the left column: the Explorer tab. Clicking on a .py file opens the script for editing.

Additional Python support can be installed by clicking Install on the bottom-right notification:

Figure 1.23: Our Python script in VS Code

Figure 1.23: Our Python script in VS Code

Keeping Blender’s text blocks in sync

When a text file open in Blender is changed by another application, a red question mark appears to the left of the filename:

Figure 1.24: Blender detects changes in a saved script

Figure 1.24: Blender detects changes in a saved script

Clicking the question mark displays the viable actions:

  • Reload from disk: This loads and displays the up-to-date file
  • Make text internal (separate copy): The displayed text is now part of the Blender session, no longer tied to any text file on disk
  • Ignore: Changes are ignored; Blender will still display the old text and keep reporting that it’s out of sync with the text saved on disk

To have additional help, we can add versioning to our files. That allows us to make changes without worrying about breaking things or losing our work.

You have been reading a chapter from
Python Scripting in Blender
Published in: Jun 2023
Publisher: Packt
ISBN-13: 9781803234229
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime