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
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
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.