From 8283d7403c91427559946ee38536a4fa5847be3c Mon Sep 17 00:00:00 2001 From: Li Date: Mon, 29 Apr 2024 17:00:35 +0200 Subject: [PATCH 1/3] allow Rhino.Geometry.Point --- src/compas_rhino/conversions/geometry.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compas_rhino/conversions/geometry.py b/src/compas_rhino/conversions/geometry.py index 118e4302e84..bb7e04bb883 100644 --- a/src/compas_rhino/conversions/geometry.py +++ b/src/compas_rhino/conversions/geometry.py @@ -103,14 +103,19 @@ def point_to_compas(point): Parameters ---------- - point : :rhino:`Rhino.Geometry.Point3d` + point : :rhino:`Rhino.Geometry.Point3d` | :rhino:`Rhino.Geometry.Point` Returns ------- :class:`compas.geometry.Point` """ - return Point(point.X, point.Y, point.Z) + if isinstance(point, Rhino.Geometry.Point3d): + return Point(point.X, point.Y, point.Z) + elif isinstance(point, Rhino.Geometry.Point): + return Point(point.Location.X, point.Location.Y, point.Location.Z) + else: + raise TypeError("Expected Rhino.Geometry.Point3d or Rhino.Geometry.Point., got: {}".format(type(point))) def vector_to_compas(vector): From 7b5b5e3e5f66e556b8616879627bf643ce76b9ea Mon Sep 17 00:00:00 2001 From: Li Date: Mon, 29 Apr 2024 17:01:57 +0200 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index afce9e69104..9cb89d700b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Changed use of `compas.geometry.allclose` to `compas.tolerance.TOL.is_allclose`. * Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`. * Changed imports of itertools to `compas.itertools` instead of `compas.utilities`. +* Updated `compas_rhino.conversions.point_to_compas` to allow for `compas.geometry.Point` as input. ### Removed From 94546998f95fc37bc9adf5265caef71a4809beb9 Mon Sep 17 00:00:00 2001 From: Licini Date: Mon, 29 Apr 2024 17:50:58 +0200 Subject: [PATCH 3/3] use try except --- CHANGELOG.md | 2 +- src/compas_rhino/conversions/geometry.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cb89d700b2..8baf02dc1b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Changed use of `compas.geometry.allclose` to `compas.tolerance.TOL.is_allclose`. * Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`. * Changed imports of itertools to `compas.itertools` instead of `compas.utilities`. -* Updated `compas_rhino.conversions.point_to_compas` to allow for `compas.geometry.Point` as input. +* Updated `compas_rhino.conversions.point_to_compas` to allow for `Rhino.Geometry.Point` as input. ### Removed diff --git a/src/compas_rhino/conversions/geometry.py b/src/compas_rhino/conversions/geometry.py index bb7e04bb883..cceb72bbe7e 100644 --- a/src/compas_rhino/conversions/geometry.py +++ b/src/compas_rhino/conversions/geometry.py @@ -3,6 +3,7 @@ from __future__ import print_function import Rhino # type: ignore +from System import MissingMemberException # type: ignore from compas.geometry import Frame from compas.geometry import Plane @@ -110,12 +111,13 @@ def point_to_compas(point): :class:`compas.geometry.Point` """ - if isinstance(point, Rhino.Geometry.Point3d): + try: return Point(point.X, point.Y, point.Z) - elif isinstance(point, Rhino.Geometry.Point): - return Point(point.Location.X, point.Location.Y, point.Location.Z) - else: - raise TypeError("Expected Rhino.Geometry.Point3d or Rhino.Geometry.Point., got: {}".format(type(point))) + except MissingMemberException: + try: + return Point(point.Location.X, point.Location.Y, point.Location.Z) + except MissingMemberException: + raise TypeError("Unexpected point type, got: {}".format(type(point))) def vector_to_compas(vector):