Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
62 changes: 62 additions & 0 deletions src/compas_ghpython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

from compas_rhino import unload_modules # noqa: F401

try:
import Grasshopper
except ImportError:
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
except ImportError:
except ImportError:
# Grasshopper is not available in this environment; safe to ignore.

Copilot uses AI. Check for mistakes.
# We're not running inside Grasshopper, fail silently
pass

__version__ = "2.14.1"

Expand All @@ -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",
Expand Down Expand Up @@ -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)
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function uses Grasshopper.Kernel.GH_RuntimeMessageLevel directly, but Grasshopper may be undefined if the import at line 12 failed. This will cause a NameError at runtime. Consider adding a check or raising a more informative error if Grasshopper is not available, or ensure these functions are only callable in Grasshopper contexts.

Copilot uses AI. Check for mistakes.


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)
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function uses Grasshopper.Kernel.GH_RuntimeMessageLevel directly, but Grasshopper may be undefined if the import at line 12 failed. This will cause a NameError at runtime. Consider adding a check or raising a more informative error if Grasshopper is not available, or ensure these functions are only callable in Grasshopper contexts.

Copilot uses AI. Check for mistakes.


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)
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function uses Grasshopper.Kernel.GH_RuntimeMessageLevel directly, but Grasshopper may be undefined if the import at line 12 failed. This will cause a NameError at runtime. Consider adding a check or raising a more informative error if Grasshopper is not available, or ensure these functions are only callable in Grasshopper contexts.

Copilot uses AI. Check for mistakes.


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
# =============================================================================
Expand Down
Loading