Grasshopper

algorithmic modeling for Rhino

please, what would be the correct way of determining if a geometry is a Plane?

the way I have done it Grasshopper detects even a planar surface as an endless Plane

pManager.AddGeometryParameter("Reference geometry", "G", "", GH_ParamAccess.list);

List<Object> geometry = new List<object>();

foreach (Object geo in geometry)
     {

     Grasshopper.Kernel.Types.GH_Plane ghPlane = new Grasshopper.Kernel.Types.GH_Plane();
     ghPlane.CastFrom(geo);
     if (ghPlane.IsValid) { ghPlane.CastTo<Plane>(out testPlane);
          if (testPlane.IsValid)
               {

thanks!

Views: 434

Replies to This Discussion

Try/catch should work:

private void RunScript(List<object> x, ref object A)
{

var ValidPlanes = new List<Plane>();

foreach(object TestItem in x)
{
Plane TestPlane;
try
{
TestPlane = (Plane) TestItem;
}
catch
{
continue;
}
ValidPlanes.Add(TestPlane);
}

A = ValidPlanes;

}

Attachments:

yup, thanks. that did the trick!
except the types were GH_Plane etc.

I would argue most elegant way is this one liner with linq:

A = x.OfType<Plane> ();

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service