First Steps: ValueError("No context detected.")

Hello. Just trying out the COMPAS v2 by following the docs and hit an error on the very first steps.
I don’t see where it went wrong (according to the documentation):

$ conda create -n compas-2 -c conda-forge python=3.10 compas
$ conda activate compas-2
$ python a_simple_box.py

Error:

Traceback (most recent call last):
  File "~/a_simple_box.py", line 8, in <module>
    scene.draw()
  File "~/Applications/miniconda3/envs/compas-2/lib/python3.10/site-packages/compas/scene/scene.py", line 131, in draw
    raise ValueError("No context detected.")
ValueError: No context detected.

a_simple_box.py

from compas.geometry import Box
from compas.scene import Scene

box = Box(1, 1, 1)

scene = Scene()
scene.add(box)
scene.draw()

I share this because I don’t want anybody to turn away from compas while following the docs to get started; as I think it’s a fantastic project on which I built my research !

Hi @mononym

Sorry you’re having an issue trying the example.
Using the Scene alone requires some kind of a visualization context to be available (CAD).

If you run the example code within Rhino/Grasshopper/Blender, the Scene should automatically detect one of them as the current context.

For standalone COMPAS visualization you can always use compas_viewer:

Install compas_viewer

pip install compas_viewer

Your script then would need to look like that:

from compas.geometry import Box
from compas_viewer.viewer import Viewer

box = Box(1, 1, 1)

viewer = Viewer()
viewer.scene.add(box)
viewer.show()

It is mentioned in the First Steps page but I’ll see if we can make the note there a bit clearer.

2 Likes