Skip to content

Commit 1d56e99

Browse files
committed
added some UI helpers for GH components
1 parent c0d480d commit 1d56e99

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
* Added `compas_rhino.install_with_pip` with corresponding command line utility `install_in_rhino`.
1313
* Added support for `.stp` file extension in addition to `.step` for `RhinoBrep.from_step()` and `RhinoBrep.to_step()` methods.
1414
* Added `volume()` method to `compas.datastructures.Mesh` for computing the volume of closed meshes using signed volume of triangles.
15+
* Added functions `warning`, `message`, `error` and `remark` to `compas_ghpython`.
1516

1617
### Changed
1718

src/compas_ghpython/__init__.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
from compas_rhino import unload_modules # noqa: F401
1010

11+
try:
12+
import Grasshopper
13+
except ImportError:
14+
pass
1115

1216
__version__ = "2.14.1"
1317

@@ -16,6 +20,11 @@
1620
"get_grasshopper_library_path",
1721
"get_grasshopper_userobjects_path",
1822
"fetch_ghio_lib",
23+
"create_id",
24+
"warning",
25+
"error",
26+
"remark",
27+
"message",
1928
]
2029
__all_plugins__ = [
2130
"compas_ghpython.install",
@@ -56,6 +65,58 @@ def create_id(component, name):
5665
return "{}_{}".format(name, component.InstanceGuid)
5766

5867

68+
def warning(component, message):
69+
"""Add a warning message to the component.
70+
71+
Parameters
72+
----------
73+
component : Grasshopper.Kernel.IGH_Component
74+
The component instance. Pre-Rhino8 use `self`. Post-Rhino8 use `ghenv.Component`.
75+
message : str
76+
The message to display.
77+
"""
78+
component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Warning, message)
79+
80+
81+
def error(component, message):
82+
"""Add an error message to the component.
83+
84+
Parameters
85+
----------
86+
component : Grasshopper.Kernel.IGH_Component
87+
The component instance. Pre-Rhino8 use `self`. Post-Rhino8 use `ghenv.Component`.
88+
message : str
89+
The message to display.
90+
"""
91+
component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, message)
92+
93+
94+
def remark(component, message):
95+
"""Add a remark message to the component.
96+
97+
Parameters
98+
----------
99+
component : Grasshopper.Kernel.IGH_Component
100+
The component instance. Pre-Rhino8 use `self`. Post-Rhino8 use `ghenv.Component`.
101+
message : str
102+
The message to display.
103+
"""
104+
component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Remark, message)
105+
106+
107+
def message(component, message):
108+
"""Add a text that will appear under the component.
109+
110+
Parameters
111+
----------
112+
component : Grasshopper.Kernel.IGH_Component
113+
The component instance. Pre-Rhino8 use `self`. Post-Rhino8 use `ghenv.Component`.
114+
message : str
115+
The message to display.
116+
"""
117+
component.Message = message
118+
119+
59120
# =============================================================================
60121
# Managed Plugin
61122
# =============================================================================

0 commit comments

Comments
 (0)