algorithmic modeling for Rhino
Hello,
I am attempting to grab various geometries from layers in Rhino and using them as input in a C# component. I used code provided here on the forums in VB and translated it to C# to grab objects from layers:
String layer = "Points";
Int32 layer_index = doc.Layers.Find(layer, true);
if ((layer_index < 0))
return;Rhino.DocObjects.Layer lay = doc.Layers[layer_index];
Rhino.DocObjects.RhinoObject[] objs = doc.Objects.FindByLayer(lay);
if ((objs == null))
return;List<GeometryBase> geo = new List<GeometryBase>();
foreach (Rhino.DocObjects.RhinoObject obj in objs) {
geo.Add(obj.Geometry);
}A = geo;
My issue here is that the grabbed "objects" should be casted to Point3d, and I can't figure out how this is done. Can someone help me with:
Thanks!
Tarek
Tags:
Hi Tarek,
You can use the Grasshopper Types to cast from GeometryBase to Rhinocommon types.
1. Method:
    List<Point3d> geo = new List<Point3d>();
    foreach (Rhino.DocObjects.RhinoObject obj in objs) {
      GH_Point p = new GH_Point();
      p.CastFrom(obj.Geometry);
      geo.Add(p.Value);
    }
2. Method:
    List<Point3d> geo = new List<Point3d>();
    foreach (Rhino.DocObjects.RhinoObject obj in objs) {
      GH_Point p = new GH_Point(obj.Id);
      p.LoadGeometry(doc);
      geo.Add(p.Value);
    }
 
Cheers FF
Thanks a lot Florian!
See I am not sure where I can get this kind of information (specifically about GH Types and casts), this forum helps a lot and I am very grateful. 
Quick fix just in case someone looks this up:
List<Point3d> geo = new List<Point3d>();
foreach (Rhino.DocObjects.RhinoObject obj in objs) {
GH_Point p = new GH_Point();
p.CastFrom(obj.Geometry);
geo.Add(p.Value);
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
    © 2025               Created by Scott Davidson.             
    Powered by