Blender

Blender ships with its own embedded version of Python but it is relatively simple to replace it with the one you have COMPAS installed on.

Note

The latest releases of COMPAS only support Blender 2.8. This version of Blender requires Python 3.7.x.

Replace Python

It is recommended to create a new conda environment to make sure the python version matches exactly what Blender expects.

Open the command prompt and type the following to install a new python environment with COMPAS:

conda config --add channels conda-forge
conda create -n blender python=3.7 COMPAS
conda activate blender

Now configure Blender to use the newly installed environment:

cd %PROGRAMFILES%\Blender Foundation\Blender\2.80
ren python original_python
mklink /j python %CONDA_PREFIX%

Open the Terminal and type the following to install a new python environment with COMPAS:

conda config --add channels conda-forge
conda create -n blender python=3.7 COMPAS
conda activate blender

Now configure Blender to use the newly installed environment:

cd /Applications/blender.app/Contents/Resources/2.80
mv python original_python
ln -s $CONDA_PREFIX python

Verify setup

In Blender, you should now be able to use COMPAS packages without any problems. Simply create and run the following script to verify everything is working properly.

import compas

from compas.datastructures import Mesh
from compas_blender.artists import MeshArtist

mesh = Mesh.from_obj(compas.get('faces.obj'))

artist = MeshArtist(mesh)

artist.draw_vertices()
artist.draw_edges()
artist.draw_faces()
../../_images/blender_verify.png

Install Python packages

After replacing the embedded version of Python with the one in the virutual environment, as instructed above, it is not necessary to activate the environment before using Blender. However, when you want to update the installed packages, or add more packages, make sure you do it for the Python in the virtual environment. Otherwise, the changes will not have any effect.

conda activate blender
conda install ...

Start Blender

Both on Windows and Mac (for different reasons) Blender should be started from the command line. By adding the Blender executable to the PATH variable this is really simple.

Add the path to the Blender executable to your PATH in Environment Variables.

%PROGRAMFILES%\Blender Foundation\Blender

Add the following to your .bash_profile

export PATH="/Applications/blender.app/Contents/MacOS:$PATH"

After that starting Blender from the command line is much simpler.

blender