compas-dev / compas

Core packages of the COMPAS framework.
https://compas.dev/compas/
MIT License
313 stars 108 forks source link

Cannot convert from Rhino.Point to compas point using `point_to_compas` #1343

Closed xarthurx closed 6 months ago

xarthurx commented 6 months ago

Describe the bug

point_to_compas can convert Point3d to compas-point object. However, when the point is converted from rs.coercerhinoobject(pt).Geometry inside a GHpython script, the default result is Rhino.Geometry.Point instead of Rhino.Geometry.Point3d

using the current code of point_to_compas, this will result in a error: AttributeError: 'Point' object has no attribute 'X'

Based on here, in such case, we need to use pt.Location to get the coordinate, which is also a valid input for point_to_compas.

To Reproduce Steps to reproduce the behavior:

  1. In GHPython, make a python script (IronPython): image
  2. Inside:
# if Guid, convert to Rhino Object
import compas_rhino.conversions as cnv 
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import System.Guid

if type(obj) == System.Guid:
    obj = rs.coercerhinoobject(obj).Geometry

obj_type = type(obj)
if obj_type == rg.Point:
    print("converting to point")
    res1 = cnv.point_to_compas(obj)
    res2 = cnv.point_to_compas(obj.Location)

Expected behavior res1 should work. But only res is working.

Screenshots image

Desktop (please complete the following information):

Additional context Should be a simple fix. So I didn't bother to create a PR. If you need, a PR is also possible.

Licini commented 6 months ago

@xarthurx Fixed now, let me know if there is still any issue with this.