Skip to content

Commit 565586e

Browse files
authored
Merge pull request #1501 from compas-dev/gh_helpers
added some UI helpers for GH components
2 parents c0d480d + e867244 commit 565586e

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
from compas_rhino import unload_modules # noqa: F401
1010

11+
try:
12+
import Grasshopper
13+
except ImportError:
14+
# We're not running inside Grasshopper, fail silently
15+
pass
1116

1217
__version__ = "2.14.1"
1318

@@ -16,6 +21,11 @@
1621
"get_grasshopper_library_path",
1722
"get_grasshopper_userobjects_path",
1823
"fetch_ghio_lib",
24+
"create_id",
25+
"warning",
26+
"error",
27+
"remark",
28+
"message",
1929
]
2030
__all_plugins__ = [
2131
"compas_ghpython.install",
@@ -56,6 +66,58 @@ def create_id(component, name):
5666
return "{}_{}".format(name, component.InstanceGuid)
5767

5868

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

0 commit comments

Comments
 (0)