From 1d56e9959217a47561a3fc99824078f6a488eed9 Mon Sep 17 00:00:00 2001 From: Chen Kasirer Date: Tue, 4 Nov 2025 15:13:15 +0100 Subject: [PATCH 1/2] added some UI helpers for GH components --- CHANGELOG.md | 1 + src/compas_ghpython/__init__.py | 61 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbd791a9d10f..65f01c430089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Added `compas_rhino.install_with_pip` with corresponding command line utility `install_in_rhino`. * Added support for `.stp` file extension in addition to `.step` for `RhinoBrep.from_step()` and `RhinoBrep.to_step()` methods. * Added `volume()` method to `compas.datastructures.Mesh` for computing the volume of closed meshes using signed volume of triangles. +* Added functions `warning`, `message`, `error` and `remark` to `compas_ghpython`. ### Changed diff --git a/src/compas_ghpython/__init__.py b/src/compas_ghpython/__init__.py index 228ce44f51df..a9da9033c15e 100644 --- a/src/compas_ghpython/__init__.py +++ b/src/compas_ghpython/__init__.py @@ -8,6 +8,10 @@ from compas_rhino import unload_modules # noqa: F401 +try: + import Grasshopper +except ImportError: + pass __version__ = "2.14.1" @@ -16,6 +20,11 @@ "get_grasshopper_library_path", "get_grasshopper_userobjects_path", "fetch_ghio_lib", + "create_id", + "warning", + "error", + "remark", + "message", ] __all_plugins__ = [ "compas_ghpython.install", @@ -56,6 +65,58 @@ def create_id(component, name): return "{}_{}".format(name, component.InstanceGuid) +def warning(component, message): + """Add a warning message to the component. + + Parameters + ---------- + component : Grasshopper.Kernel.IGH_Component + The component instance. Pre-Rhino8 use `self`. Post-Rhino8 use `ghenv.Component`. + message : str + The message to display. + """ + component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Warning, message) + + +def error(component, message): + """Add an error message to the component. + + Parameters + ---------- + component : Grasshopper.Kernel.IGH_Component + The component instance. Pre-Rhino8 use `self`. Post-Rhino8 use `ghenv.Component`. + message : str + The message to display. + """ + component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, message) + + +def remark(component, message): + """Add a remark message to the component. + + Parameters + ---------- + component : Grasshopper.Kernel.IGH_Component + The component instance. Pre-Rhino8 use `self`. Post-Rhino8 use `ghenv.Component`. + message : str + The message to display. + """ + component.AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Remark, message) + + +def message(component, message): + """Add a text that will appear under the component. + + Parameters + ---------- + component : Grasshopper.Kernel.IGH_Component + The component instance. Pre-Rhino8 use `self`. Post-Rhino8 use `ghenv.Component`. + message : str + The message to display. + """ + component.Message = message + + # ============================================================================= # Managed Plugin # ============================================================================= From e867244582b5700d30b605fbc325f6293ae3cbb8 Mon Sep 17 00:00:00 2001 From: Chen Kasirer Date: Wed, 5 Nov 2025 09:52:10 +0100 Subject: [PATCH 2/2] added comment --- src/compas_ghpython/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compas_ghpython/__init__.py b/src/compas_ghpython/__init__.py index a9da9033c15e..45cbd675ce1a 100644 --- a/src/compas_ghpython/__init__.py +++ b/src/compas_ghpython/__init__.py @@ -11,6 +11,7 @@ try: import Grasshopper except ImportError: + # We're not running inside Grasshopper, fail silently pass __version__ = "2.14.1"