/// <summary> /// You will need to override this method to solve the component. /// </summary> /// <param name="DA">Grasshopper's DataAccess interface</param> protected override void SolveInstance(GH.Kernel.IGH_DataAccess DA) { // Retrieve the data and pass it to the designer component Point3d point = new Point3d(0, 0, 0); double span = 10.0; double height = 1.0; int n = 1; double spacing = 1.0; if (DA.GetData<Point3d>(1, ref point)) { ((DesignerWithVisualOutputExample)this.Designer).basePoint = new SOPoint3d( point.X, point.Y, point.Z); } if (DA.GetData<double>(2, ref span)) { ((DesignerWithVisualOutputExample)this.Designer).Span = span; } if (DA.GetData<double>(3, ref height)) { ((DesignerWithVisualOutputExample)this.Designer).Height = height; } if (DA.GetData<int>(4, ref n)) { ((DesignerWithVisualOutputExample)this.Designer).NumberOfFrames = n; } if (DA.GetData<double>(5, ref spacing)) { ((DesignerWithVisualOutputExample)this.Designer).Spacing = spacing; } /// Note that you will need to call the SolveInstance method of the base class to process the default parameters and connect them to the framework. base.SolveInstance(DA); DesignerWithVisualOutputExample dsn = (DesignerWithVisualOutputExample)this.Designer; List<Line> lines = new List<Line>(); for (int i = 0; i < dsn.NumberOfFrames; i++) { lines.Add(new Line(dsn.Points2[i].X, dsn.Points2[i].Y, dsn.Points2[i].Z, dsn.Points4[i].X, dsn.Points4[i].Y, dsn.Points4[i].Z)); lines.Add(new Line(dsn.Points1[i].X, dsn.Points1[i].Y, dsn.Points1[i].Z, dsn.Points2[i].X, dsn.Points2[i].Y, dsn.Points2[i].Z)); lines.Add(new Line(dsn.Points3[i].X, dsn.Points3[i].Y, dsn.Points3[i].Z, dsn.Points4[i].X, dsn.Points4[i].Y, dsn.Points4[i].Z)); } DA.SetDataList(1, lines); }
protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA) { double v = -1.0; DA.GetData(1, ref v); if (!FriedChiken.isInitialized) { Rhino.Geometry.Curve c = null; if (!DA.GetData(0, ref c)) return; if (c.IsPolyline()) { Rhino.Geometry.Polyline pl = null; if (c.TryGetPolyline(out pl)) { nNewNodes = pl.Count(); nElements = nNewNodes - 1; newNodes.Clear(); newNodes.AddRange(pl); lGeometry.Clear(); for (int i = 0; i < nElements; i++) { lGeometry.Add(new Rhino.Geometry.Line(newNodes[i], newNodes[i + 1])); } mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes]; for (int i = 0; i < nNewNodes; i++) { particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]); } List<mikity.NumericalMethodHelper.elements.isoparametricElement> e = new List<mikity.NumericalMethodHelper.elements.isoparametricElement>(); for (int i = 0; i < nElements; i++) { e.Add(new mikity.NumericalMethodHelper.elements.isoparametricElement(i, i + 1)); } lCV.Clear(); pS = new GH_particleSystem(particles); for (int i = 0; i < e.Count; i++) { lCV.Add(new constrainVolumeObject(v / nElements)); lCV[i].addElement(e[i]); pS.Value.addObject(lCV[i]); } lGeometry.Clear(); for (int i = 0; i < nElements; i++) { lGeometry.Add(new Rhino.Geometry.Line(pS.Value.particles[i, 0], pS.Value.particles[i, 1], pS.Value.particles[i, 2], pS.Value.particles[i + 1, 0], pS.Value.particles[i + 1, 1], pS.Value.particles[i + 1, 2])); } } } else { AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Only polyline is accepted"); return; } } else { if (lCV != null && v > 0) { for (int i = 0; i < lCV.Count; i++) { lCV[i].refVolume = v / nElements; } } } DA.SetData(0, pS); DA.SetDataList(1, newNodes); }