Skip to content

Scene context detection #1467

Description

@tomvanmele
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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions