compas-dev / compas-dev/compas

`Runtime error (NotSupportedException)` in Grasshopper when using `draw_labels`

Open
#1,354 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
386
Forks
122
Avg merge
11d 46m
Merged PRs (30d)
1

Description

Getting a runtime error when trying to draw a text label in Rhino with Grasshopper.

Can be reproduced by running the following code in a GHPython component:
```python
from compas_rhino.utilities import draw_labels

draw_labels([{"pos": [0, 0, 0], "text": "this is a text"}])
```
The full error:
```
Runtime error (NotSupportedException): This type of object is not supported in Grasshopper, so this Python script cannot create it. You might want to use 'scriptcontext.doc = Rhino.RhinoDoc.ActiveDoc' to use the Rhino doc, instead? If you do, remember to restore it: 'scriptcontext.doc = ghdoc'.

Traceback:
line 110, in draw_labels, "C:\Users\ckasirer\AppData\Roaming\McNeel\Rhinoceros\7.0\scripts\compas_rhino\utilities\drawing.py"
line 57, in wrapper, "C:\Users\ckasirer\AppData\Roaming\McNeel\Rhinoceros\7.0\scripts\compas_rhino\utilities\drawing.py"
line 3, in script
```
**Desktop (please complete the following information):**
- OS: Window 7
- Rhino 7 SR36

**Additional context**
The suggested solution in the error (setting `scriptcontext.doc` to `RhinoDoc.ActiveDoc`) doesn't produce a different result.
However, this code works:
```python
import Rhino

text = Rhino.Geometry.TextDot("this is a text", Rhino.Geometry.Point3d(0, 0, 0))
Rhino.RhinoDoc.ActiveDoc.Objects.AddTextDot(text)
```

![image](https://github.com/compas-dev/compas/assets/3398309/cf11ae44-253c-4712-887e-b6f4b173a49e)

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.