georgevdd / blender-eclipse

Blender/Eclipse integration
GNU General Public License v3.0
6 stars 1 forks source link

Overview

Blender's Python editor is functional, but not the best available. The tools and guidelines in this repository are for connecting Blender to Eclipse, bringing superior tools to bear on your Blender scripts.

These tools build on the instructions on the Blender Wiki and the original book of Eclipse/Blender instructions by Witold Jaworski.

Advantages include:

Prerequisites


NOTE: These instructions assume for the sake of example that Blender is version 2.77 and that it's installed on OSX at /Applications/Blender/blender.app, but it should not be hard to work out how to adapt the paths in this document to match your own installation.


Download

cd path/to/repo ; git clone'https://github.com/georgevdd/blender-eclipse.git'.

Eclipse Setup

These steps should only need to be done once per Eclipse installation.


TODO: Make an Eclipse plugin that does these steps, or at least checks that they've been done.


Autocompletion for Blender APIs

  1. Fetch the API building script:

git clone'https://github.com/mutantbob/pycharm-blender.git'.

  1. Run it within Blender:

/Applications/Blender/blender.app/Contents/MacOS/blender -b -P python_api/pypredef_gen.py

This will create a directory called pypredef which will be useful when setting up the Python interpreter, next.


NOTE: Something that Jaworski's book doesn't mention: You can use assert isinstance(x, XType) or if isinstance(x, XType): to help PyDev reason about the types of variables. With Python 3.5 or later you can use type hints too.



TODO: bring pypredef_gen.py into this repository and make running it easier.


Python Interpreter

The Python interpreter that Eclipse will use needs to be the same version as the one that Blender uses. The easy way to achieve that is to set up Eclipse to use the interpreter that comes with Blender:

Eclipse Project Setup

These steps need to be done for each Eclipse PyDev project that you want to use with Blender.


TODO: Make an Eclipse plugin that does these steps, or at least checks that they've been done.


Interpreter

Debugger


NOTE: The new Run Configuration must be given a valid "Project" field, otherwise it will silently not set up its environment variables properly. It's not clear to me why this is.


Blender Setup

These steps should only need to be done once per Blender installation.

  1. Install the Eclipse Connector addon:
cd /Users/georgevdd/Library/Application Support/Blender/2.77/scripts/addons
ln -s path/to/repo/eclipse_connector.py .

Usage

  1. Make sure the PyDev debugger server is running:
    • Window -> Perspective -> Open Perspective -> Debug
    • PyDev -> Start Debug Server
  2. Launch Blender from Eclipse

    • Click on the PyBlend project
    • (Run icon) -> Blender Subprocess

    Standard output from Blender should appear in the Eclipse console view. You should see a small amount of logging from Eclipse Connector.

  3. Within Blender, when you choose "Run Script", control will break into the Eclipse debugger when any breakpoint is hit. You can now step through your script within the debugger. When you choose Resume (F8) within Eclipse, control returns to Blender.

Reloading Code Without Restarting Blender

If you make changes to a Python script in Eclipse after you have run the script in Blender, Blender will not automatically notice those changes. The next time you try to run the script in Blender, you will see that it runs the old code. (This is because Blender is secretly less of a graphics program with a Python subsystem in it, than a Python interpreter with a graphics subsystem in it.)

To work around this, have Blender run the script indirectly by Executing External Scripts.