How cast GeometryBase to Point3d

Hi everyone,

I am using RhinoIdle to collect selected objects like Curve, Brep, Point3d etc…
Casting from GeometryBase to Curve and Brep is successful but I cannot cast to Point3d in order to collect selected points to my lists. How possibly can I collect selected points in my dictionary. I put sample of in order to compare Curve and Point3d in RhinoIdle event handler.

private void OnIdle(object sender, EventArgs e)
    #region Curve Selection
    List<Curve> curves = new List<Curve>();
    Dictionary<Guid, Curve> selectedCurves = new Dictionary<Guid, Curve>();

    List<RhinoObject> selectedRhinoObjectCurves = RhinoDoc.ActiveDoc.Objects.GetObjectsByType<RhinoObject>(new ObjectEnumeratorSettings()
        ObjectTypeFilter = ObjectType.Curve,
        SelectedObjectsFilter = true

    foreach (RhinoObject rhinoObject in selectedRhinoObjectCurves)
        Guid guidCurve = rhinoObject.Id;
        Curve curve = (Curve)rhinoObject.Geometry; //// SUCCESSFULL CASTING
        selectedCurves.Add(guidCurve, curve);
    SelectedCurves = selectedCurves;
    #endregion Curve Selection

    #region Point Selection
    List<Point3d> points = new List<Point3d>();
    Dictionary<Guid, ILocation> selectedPoints = new Dictionary<Guid, ILocation>();

    List<RhinoObject> selectedRhinoObjectPoints = RhinoDoc.ActiveDoc.Objects.GetObjectsByType<RhinoObject>(new ObjectEnumeratorSettings()
        ObjectTypeFilter = ObjectType.Point,
        SelectedObjectsFilter = true

    foreach (RhinoObject rhinoObject in selectedRhinoObjectPoints)
        Guid guidPoint = rhinoObject.Id;
        Point3d point = (Point3d)rhinoObject.Geometry;  //// FAILED CASTING      
        selectedPoints.Add(guidPoint, point);
    SelectedPoints = selectedPoints;

    #endregion Point Selection

Thanks in advance,

1 Like

You cannot cast to Point3d, because Point3d is a struct which does not derive from GeometryBase. You must cast to the Rhino.Geometry.Point class instead, and then extract the Point3d coordinate later.


@DavidRutten, thanks for quick answer and solution.

Point point = (Rhino.Geometry.Point)rhinoObject.Geometry;
Point3d point3d = point.Location;