How to convert Geometrybase into point3d?

%E5%9B%BE%E7%89%87
I have to convert a Geometry parameter object into point3d,but failed,i check the reason ,may be: Point3d doesnot inherit the “Geometrybase” class
but how to convert a point wraped in geometry parameter component into a point3d?
Thank you!

the problem code in c# script component:
private void RunScript(GeometryBase x, ref object A)
{
if(x is Point3d)
{
Point3d pt = (Point3d) x;
}
A = pt;
}
convertGeoToPoint.gh (3.1 KB)

The point here is Rhino.Geometry.Point instead of Rhino.Geometry.Point3d. Your code should be

Point3d pt = Point3d.Unset;
if(x is Rhino.Geometry.Point)
{
    pt = ((Rhino.Geometry.Point) x).Location;
}
A = pt;

PS: It’s sad that C# in GH is too old to support type pattern. Otherwise you can just write:

if(x is Rhino.Geometry.Point ptObj)
    A = ptObj.Location;
1 Like

Thankyou Keyu Gan!it works!
i also find the code works well http://www.grasshopper3d.com/forum/topics/casting-problems-in-c?commentId=2985220%3AComment%3A472021

1 Like