How to Configure Visual Studio Code for Blender Add-on Creation

How to Configure VS Code for Blender Add-on Development

Step-by-Step VS Code Setup for Blender Add-on Development

Blender scripting
vscode
blender
blender addons

Starting from September 10th, 2024, I began building my own Blender add-on. Initially, I thought it would be straightforward to configure Visual Studio Code (VS Code) for developing Blender add-ons. However, I soon found that setting up VS Code for this purpose was quite tedious. After a few days of trial and error, I finally discovered a standardized and sustainable process for developing Blender add-ons using VS Code. In this blog post, I'll share my step-by-step guide to help you set up VS Code for Blender add-on development.

Steps to Set Up VS Code for Blender Add-on Development

  1. Open VS Code
  2. Activate the Blender Development Extension
    • Install the following extension: Blender Development.
    • Open the extension settings and enable the option: Reload addon in Blender when a document is saved.

    VS Code settings for Blender add-on development to reload add-ons when saved

  3. Open Your Project Folder in VS Code
  4. Create a New Add-on
    • Press Ctrl + Shift + P to open the Command Palette.
    • Search for New Addon and select Simple.

    Search for New Addon in VS Code Command Palette

    • You will be prompted to provide a name for the add-on, developer name, support for previous Blender versions, and the folder where the development files will be stored.

    This will generate the required files for a basic Blender add-on.

  5. Start Blender from VS Code
    • Open the Command Palette again with Ctrl + Shift + P and search for Blender Start.
    • You will be prompted to select the specific version of Blender where you want to install the add-on.

    Blender should now open automatically. To activate the add-on, go to Preferences > Add-ons and search for [Your Add-on Name].

    Search for the add-on in Blender and activate it

    At this point, the add-on is registered but not yet functional.

  6. Import the Blender Package
    • Open a *.py file in your project and add the following code:
      import bpy

    VS Code error about bpy not found

    If you encounter an error stating that bpy is not found, proceed to the next step.

  7. Select the Python Interpreter
    • Press Ctrl + Shift + P to open the Command Palette and search for Select Interpreter.VS Code Command Palette to select Python interpreter
    • Choose the Python version installed on your system (typically located inside the C: drive on Windows).
    • Open the Windows Terminal with "Run as Administrator" privileges and run the following command:
      pip install fake-bpy-module
      This command installs a fake version of the bpy module, which simulates the Blender Python API. You can find more details about this package here.
  8. Verify Everything is Working
    • Open VS Code again, and everything should now be functioning correctly!