[PYTHON] [Blender] Prepare the Blender script debugging environment (Eclipse + PyDev)

As Blender scripts grow in size, it's time to use the debugger. Until now, when I created a Blender script, I used to focus on self.report, so I was feeling the limits. So I used ** Eclipse + PyDev ** to build a debug environment for Blender script development.

Debug environment construction

Download eclipse

Download the latest version of Eclipse from the Eclipse home page.

Eclipse download page

You may be prompted to install Java SE if needed, in which case follow the instructions to install.

Java SE Download Page

Install PyDev

Follow the steps below to install ** PyDev **.

  1. Click Help-ʻInstall New Software ...`
  2. Click ʻAdd ... in the ʻAvailable Software window
  3. Enter ** PyDev ** for Name and ** http://pydev.org/updates ** for Location and click ʻOK`.
  4. After a while, PyDev will be added to the ʻAvailable Software window. After selecting it, uncheck the Contact all update sites during install to find required softwareand clickNext>`.
  1. Click Next> in the ʻInstall Details` window.
  2. Click Finish after accepting the license in the Review Licenses window.
  3. PyDev will be installed, so ** Restart Eclipse ** after installation **

Preparing to run debug

Creating a debug project

Create a project for debug execution.

Creating an Eclipse project

  1. Click File -- New --Project ...
  2. From the Select a wizard window, select PyDev-PyDev Project and clickNext>
  3. Give the Project name an appropriate name and then clickNext>
  4. Click Finish

Set Blender path

  1. Click Project -- Properties
  2. Select PyDev --PYTHONPATH from the menu on the left
  3. Select ʻExternal Libraries`
  4. Select ʻAdd source folder` and add the following path

Source modification for debugging

Creating a source to connect to the debug server

Create a source to connect to the PyDev debug server. Place the created source in the same directory ** as the Blender script you are debugging **.

debug.py


import sys

DEBUGGING = True

def start_debug():
    if DEBUGGING is True:
        PYDEV_SRC_DIR = "(Path to eclipse directory)/plugins/org.python.pydev_XXXXX/pysrc"    #Need to be rewritten according to the environment
        if PYDEV_SRC_DIR not in sys.path:
            sys.path.append(PYDEV_SRC_DIR)
            import pydevd
            pydevd.settrace()
            print("started blender script debugging...")

Modify the Blender script to be debugged

To start debugging, add start_debug () to ** where to start debugging ** in the script you are debugging. For example, if you want to start debugging immediately after starting script execution, do as follows.

start_debug_at_main.py


from . import debug

if __name__ == "__main__":
    debug.startdebug()

Start the PyDev debug server

Register Blender in Eclipse

Add Blender to an external tool in Eclipse. Here's how to add it:

  1. Click Run --ʻExternal Tools --ʻExternal Tools Configurations ...
  2. From the left menu, double-click Program
  3. Select the Main tab and enter ** Blender executable file ** in Location and ** the directory where the Blender executable file is located ** in Working Directory. Enter your favorite name in Name (here, ** New_Configuration **)
  4. Click ʻApply`

Start debug server

Start the PyDev debug server. The startup procedure is shown below.

  1. Click Window --ʻOpen Perspective --ʻOther ...
  2. Select Debug to open the Debug perspective
  3. Click Pydev -- Start Debug Server to start the server

Debug execution

Launch Blender

Follow the steps below to launch Blender from Eclipse.

  1. Click Run --ʻ External Tools`-** New_Configuration **
  2. Blender starts

Debug execution screen

Based on the explanation so far, I created a Blender script and debugged it.

20150413.png

With this feeling, you can proceed with debugging using Eclipse when you start debugging.

Finally

I was thinking of doing it someday, but I was able to cooperate with Blender and the debugger without any particular addiction. Using a debugger ** will greatly improve development efficiency compared to self.report debugging **, so why not try it out?

Reference information

Recommended Posts

[Blender] Prepare the Blender script debugging environment (Eclipse + PyDev)
Mac + Eclipse (PyDev) + Django environment construction
Prepare the development environment with anyenv
Prepare the environment for Atom for Pythonista
[Blender] Use OpenGL from inside the script
Prepare the development environment for keyhac for Mac
Building an environment to comply with the Python coding standard (PEP8) with Eclipse + PyDev
Introduction to Python Let's prepare the development environment
Prepare the execution environment of Python3 with Docker
The Blender script (2.8) that erases only the skirt is completed
[Blender] Use the text drawing module from within the script
Install Ubuntu 20.04 with GUI and prepare the development environment