C# plugin - How to get location of a point define as a RhinoObject


#1

Hi!

I’m trying to get the location (X,Y et Z) of a point. My point are store in a List<> of RhinoObject.
Is it possible to get point location from a RhinoObject ?

Thanks in advance for your help

Damien


#2

This is how I do it in vb.net. Should be almost the same. Think you can understand it.

Dim yourpoint as Rhino.DocObjects.ObjRef = list(item)
dim xyz = Yourpoint.point.location

You can go more spicific like:

Dim X = xyz.X or Yourpoint.point.location.X
Dim Y = xyz.Y or Yourpoint.point.location.Y
Dim Z = xyz.Z or Yourpoint.point.location.Z

Cheers


(Menno Deij - van Rijswijk) #3

Each RhinoObject has a member variable called Geometry. The class of this variable is GeometryBase. GeometryBase is the base class for all geometry classes. One of the geometry classes is Point, which is what you are looking for.

So, you would do the following:

List<RhinoObject> objs; //defined elsewhere
foreach(RhinoObject obj in objs)
{
    GeometryBase geometry = obj.Geometry;
    Point pt = geometry as Point; // cast to Point class - if not successful variable pt will be null
    if (null != pt) // check if cast was successful
        RhinoApp.WriteLine("Location: "+pt.Location.ToString());
}

#4

Menno,

Thanks for your explanations. It’s what I was lokking for.

Damien