public void SetComponentOutputs(Schema schema, IGH_DataAccess DA, List <IGH_Param> outputParams, GH_ActiveObject component) { foreach (var datatree in schema.Values) { string outputParamName = datatree.ParamName; if (outputParamName.StartsWith("RH_OUT:")) { var chunks = outputParamName.Split(new char[] { ':' }); outputParamName = chunks[chunks.Length - 1]; } int paramIndex = 0; for (int i = 0; i < outputParams.Count; i++) { if (outputParams[i].Name.Equals(outputParamName)) { paramIndex = i; break; } } var structure = new Grasshopper.Kernel.Data.GH_Structure <Grasshopper.Kernel.Types.IGH_Goo>(); Grasshopper.Kernel.Types.IGH_Goo singleGoo = null; foreach (var kv in datatree.InnerTree) { var tokens = kv.Key.Trim(new char[] { '{', '}' }).Split(';'); List <int> elements = new List <int>(); foreach (var token in tokens) { if (!string.IsNullOrWhiteSpace(token)) { elements.Add(int.Parse(token)); } } var path = new Grasshopper.Kernel.Data.GH_Path(elements.ToArray()); for (int gooIndex = 0; gooIndex < kv.Value.Count; gooIndex++) { var goo = GooFromReshopperObject(kv.Value[gooIndex]); singleGoo = goo; structure.Insert(goo, path, gooIndex); } } if (structure.DataCount == 1) { DA.SetData(paramIndex, singleGoo); } else { DA.SetDataTree(paramIndex, structure); } } foreach (var error in schema.Errors) { component.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, error); } foreach (var warning in schema.Warnings) { component.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, warning); } }
private void ExtractGeometry(Grasshopper.Kernel.Types.IGH_Goo iGoo, ref List <Rhino.Geometry.GeometryBase> resGeom) { if (iGoo is Grasshopper.Kernel.Types.GH_GeometryGroup group) { foreach (var geomGoo in group.Objects) { ExtractGeometry(geomGoo, ref resGeom); } return; } Rhino.Geometry.GeometryBase geometryBase = null; try { switch (iGoo.ScriptVariable()) { case Rhino.Geometry.Point3d point: geometryBase = new Rhino.Geometry.Point(point); break; case Rhino.Geometry.Line line: geometryBase = new Rhino.Geometry.LineCurve(line); break; case Rhino.Geometry.Rectangle3d rect: geometryBase = rect.ToNurbsCurve(); break; case Rhino.Geometry.Arc arc: geometryBase = new Rhino.Geometry.ArcCurve(arc); break; case Rhino.Geometry.Circle circle: geometryBase = new Rhino.Geometry.ArcCurve(circle); break; case Rhino.Geometry.Ellipse ellipse: geometryBase = ellipse.ToNurbsCurve(); break; case Rhino.Geometry.Curve curve: geometryBase = curve; break; case Rhino.Geometry.Box box: geometryBase = Rhino.Geometry.Mesh.CreateFromBox(box, 1, 1, 1); break; case Rhino.Geometry.Mesh mesh: geometryBase = mesh; break; case Rhino.Geometry.Brep brep: { if (!CompoundDrawable.IsRenderMode) { foreach (var crv in brep.GetWireframe(-1)) { resGeom.Add(crv); } } else { var previewMesh = new Rhino.Geometry.Mesh(); previewMesh.Append(Rhino.Geometry.Mesh.CreateFromBrep(brep, MeshParameters)); geometryBase = previewMesh; } break; } case Rhino.Geometry.Plane plane: { double len = 4.0; var x = new Rhino.Geometry.Interval(-len, len); var y = new Rhino.Geometry.Interval(-len, len); geometryBase = Rhino.Geometry.Mesh.CreateFromPlane(plane, x, y, 5, 5); break; } default: { System.Diagnostics.Debug.Fail("Not supported GH type", iGoo.GetType().ToString()); break; } } } catch (Exception e) { System.Diagnostics.Debug.Fail(e.Source, e.Message); } if (geometryBase != null) { resGeom.Add(geometryBase); } }