compas-dev / compas-dev/compas

Scene context detection

Open
#1,467 0 comments 1 reaction 3 assignees Claimed by @Licini View on GitHub
bug
Dominant language
Python
Stars
386
Forks
122
Avg merge
11d 46m
Merged PRs (30d)
1

Description

```python
def detect_current_context():
"""Chooses an appropriate context depending on available contexts and open instances. with the following priority:
1. Viewer
2. Plotter
3. Rhino / GH - checked explicitly since SceneObjects for both get registered when code is run from either.
4. Other

Returns
-------
str
Name of an available context, used as key in :attr:`SceneObject.ITEM_SCENEOBJECT`

"""

if compas.is_grasshopper():
return "Grasshopper"
if compas.is_rhino():
return "Rhino"
if compas.is_blender():
return "Blender"
other_contexts = [v for v in ITEM_SCENEOBJECT.keys()]
if other_contexts:
return other_contexts[0]

return None
```

The context detection code defaults to the first context found in `ITEM_SCENEOBJECT` when it is not detected to be one of Blender, Grasshopper, Rhino. Currently, on my system this is "Viewer", but the reason for this is random.

**To Reproduce**

```python
scene = Scene()
meshobj = scene.add(mesh)
```

The type of `meshobj` will be the one registered for the viewer.

**Expected behavior**

The default context should be `None`, and the type of `meshobj` should be the base type.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.