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..45cbd675ce1a 100644 --- a/src/compas_ghpython/__init__.py +++ b/src/compas_ghpython/__init__.py @@ -8,6 +8,11 @@ from compas_rhino import unload_modules # noqa: F401 +try: + import Grasshopper +except ImportError: + # We're not running inside Grasshopper, fail silently + pass __version__ = "2.14.1" @@ -16,6 +21,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 +66,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 # =============================================================================