Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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

Version control and backup

Version control helps to keep track of file changes, save snapshots of the code, and roll back to older versions if necessary. Git is the most used versioning system at present; it is free and integrated into most editors. In this section, we will use version control in combination with VS Code.

Initializing the repository

Once Git is installed, it can be used from VS Code, by activating the Source Control tab using the branch icon on the left column bar. The Initialize Repository button adds versioning to our folder:

Figure 1.25: Adding version control in VS Code

Figure 1.25: Adding version control in VS Code

The icon will change and warn us about the presence of files. We click the + icon next to the filename to add them to versioning. In Git terminology, we are going to Stage the current changes:

Figure 1.26: Staging changes in VS Code

Figure 1.26: Staging changes in VS Code

The editor shows the before/after conditions of our files. We can add a message in the text field on the top left and click the tick icon. This will Commit our changes to the project history:

Figure 1.27: Commit changes in VS Code

Figure 1.27: Commit changes in VS Code

Making changes

Let’s say we don’t want our script to delete the current objects. To do that, we delete line number 13:

bpy.ops.object.delete(use_global=False)

When the file is saved, version control detects this change. We can stage that by clicking the + icon, as before. If we select OurFirstScript.py in the left column, VS Code highlights the current changes. We add a message for this new commit and click the tick button again:

Figure 1.28: Displaying changes in VS Code

Figure 1.28: Displaying changes in VS Code

If we go back to the Explorer tab and select our script, we will see that a section called Timeline can be expanded: it contains a list of our commit messages. Selecting a commit displays the related changes, allowing us to restore old lines of code. Every change that is not committed can be easily undone using the Revert function.

Reverting uncommitted changes

Let’s add some incorrect text at line 7 and save. If, for any reason, we cannot undo that, we can right-click our file in the Version Control tab and select Discard Changes:

Figure 1.29: Discarding uncommitted changes in VS Code

Figure 1.29: Discarding uncommitted changes in VS Code

The importance of version control can be underestimated at first but becomes vital in more complex projects. It’s a wide topic that goes beyond the scope of this book, but it’s important to grasp at least the basics of it.

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
Banner background image