private static bool CheckInsideBounds(Basis outBasis, GH_Point traveller, GH_Brep bounds, ref bool add) { // check if ptOut is inside bounds, if they are given if (bounds.IsValid && !bounds.Value.IsPointInside(outBasis.Point.Value, 0.001d, false)) { Curve curve; Curve[] overlaps; Point3d[] intersections; curve = Curve.CreateControlPointCurve(new Point3d[] { traveller.Value, outBasis.Point.Value }); Rhino.Geometry.Intersect.Intersection.CurveBrep(curve, bounds.Value, 0.001d, out overlaps, out intersections); // if we're outside the bounds, but there is an intersection, add that intersection point to the results // if there are no intersections it's because we're starting from outside the bounds, don't add these if (intersections.Length > 0) { outBasis.Point.Value = intersections[0]; add = true; } return(true); } return(false); }
void GetSelectedRevitElements(UIDocument uidoc) { Selection selection = uidoc.Selection; ICollection <ElementId> selectedIds = uidoc.Selection.GetElementIds(); //outVals.Add("Num Selection: " + selectedIds.Count.ToString()); ghbreps = new List <GH_Brep>(); foreach (ElementId id in selectedIds) { Autodesk.Revit.DB.Options opt = new Options(); Autodesk.Revit.DB.GeometryElement geomElem = uidoc.Document.GetElement(id).get_Geometry(opt); //outVals.Add("Num Geo: " + geomElem.Count().ToString()); foreach (GeometryObject geomObj in geomElem) { var facePtList = new List <List <Point3d> >(); Solid geomSolid = geomObj as Solid; var breps = geomSolid.ToRhino(); foreach (var item in breps) { var ghB = new GH_Brep(item); ghbreps.Add(ghB); } //outputs = facePtList; } //TaskDialog.Show("Revit", faceInfo); //ids.Add(id.IntegerValue); } }
/// <summary> /// Casts the <see cref="Slot"/> to a <see cref="GH_Point"/> (from /// <see cref="AbsoluteCenter"/>, to a <see cref="Box"/> (from /// <see cref="Cage"/>) or to a <see cref="Brep"/> (from /// <see cref="Cage"/>). Required by Grasshopper for automatic type /// casting. /// </summary> /// <param name="target">The target Grasshopper geometry.</param> /// <returns>True when successful.</returns> public bool CastTo <T>(out T target) { if (typeof(T) == typeof(GH_Point)) { var absoluteCenter = new GH_Point(AbsoluteCenter); target = (T)absoluteCenter.Duplicate(); return(true); } if (typeof(T) == typeof(GH_Vector)) { var diagonal = new GH_Vector(Diagonal); target = (T)diagonal.Duplicate(); return(true); } if (typeof(T) == typeof(GH_Box)) { var box = new GH_Box(Cage); target = (T)box.Duplicate(); return(true); } if (typeof(T) == typeof(GH_Brep)) { var boxBrep = new GH_Brep(Cage.ToBrep()); target = (T)boxBrep.Duplicate(); return(true); } target = default; return(false); }
public bool ToGH_Brep <T>(ref T target) { object obj = new GH_Brep(ToBrep()); target = (T)obj; return(true); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <IGH_GeometricGoo> geometry = new List <IGH_GeometricGoo>(); Curve curve = null; if (!DA.GetDataList(0, geometry) || !DA.GetData(1, ref curve)) { return; } ////////////////将于指定曲线线有关系的物件选出(Brep,Curve,Mesh)strict 选出完全重合,some 局部重合 ,all 相关联所有 List <IGH_GeometricGoo> collect = new List <IGH_GeometricGoo>(); List <int> indexes = new List <int>(); for (int i = 0; i < geometry.Count; i++) { IGH_GeometricGoo obj = geometry[i]; if (obj is GH_Curve) { GH_Curve ghcurve = (GH_Curve)obj; if (CurveAndCurve(ghcurve.Value, curve, strict, some, all)) { indexes.Add(i); collect.Add(obj); } } else if (obj is GH_Brep) { GH_Brep ghbrep = (GH_Brep)obj; if (CurveAndBrep(ghbrep.Value, curve, strict, some, all)) { indexes.Add(i); collect.Add(obj); } } else if (obj is GH_Surface) { GH_Surface ghsurface = (GH_Surface)obj; if (CurveAndBrep(ghsurface.Value, curve, strict, some, all)) { indexes.Add(i); collect.Add(obj); } } else if (obj is GH_Mesh) { GH_Mesh ghmesh = (GH_Mesh)obj; if (CurveAndMesh(ghmesh.Value, curve, strict, some, all)) { indexes.Add(i); collect.Add(obj); } } } DA.SetDataList(0, collect); DA.SetDataList(1, indexes); }
public bool ToGH_Brep <T>(ref T target) { if (BaseSrfcs.Count == 1) { object obj = new GH_Brep(BaseSrfcs[0].ToBrep()); target = (T)obj; return(true); } return(false); }
public bool ToGH_Brep <T>(ref T target) { if (Polygon.Count == 1) { object obj = new GH_Brep(Polygon[0]); target = (T)obj; return(true); } return(false); }
private void FilterValue(GH_Structure <GH_Brep> breps, GH_Structure <GH_Integer> stories, GH_Structure <GH_String> materials, IReadOnlyList <GH_Structure <GH_Brep> > filteredBreps) { for (var i = 0; i < breps.PathCount; i++) { GH_Path path = stories.IsEmpty ? breps.Paths[i] : new GH_Path(stories.Branches[i][0].Value, i); GH_Brep brep = breps.Branches[i][0]; var materialType = materials.Branches[i][0].ToString(); SetMaterialFilteredBrep(filteredBreps, brep, materialType, path); } }
public override bool CastTo <Q>(ref Q target) { if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh))) { Mesh[] meshes = Value.GetMesh(); Mesh m = new Mesh(); for (int i = 0; i < meshes.Length; ++i) { m.Append(meshes[i]); } object mesh = new GH_Mesh(m); target = (Q)mesh; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GlulamWorkpiece))) { object blank = Value; target = (Q)blank; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Brep))) { Brep[] breps = Value.GetBrep(); Brep b = new Brep(); for (int i = 0; i < breps.Length; ++i) { b.Append(breps[i]); } object brep = new GH_Brep(b); target = (Q)brep; return(true); } //if (typeof(Q).IsAssignableFrom(typeof(GH_))) if (typeof(Q).IsAssignableFrom(typeof(GH_Curve))) { Curve[] crvs = Value.Blank.GetAllGlulams().Select(x => x.Centreline).ToArray(); //target = crvs.Select(x => new GH_Curve(x)).ToList() as Q; object crv = new GH_Curve(crvs.FirstOrDefault()); target = (Q)(crv); return(true); } if (typeof(Q).IsAssignableFrom(typeof(List <GH_Curve>))) { Curve[] crvs = Value.Blank.GetAllGlulams().Select(x => x.Centreline).ToArray(); //target = crvs.Select(x => new GH_Curve(x)).ToList() as Q; object crv = crvs.Select(x => new GH_Curve(x)).ToList(); target = (Q)(crv); return(true); } return(base.CastTo <Q>(ref target)); }
// we set up some defaults here to make it easier for the components // they will use these defaults if they are not passed a paramaters object public DynamicSettings() { respawn = true; newSpawn = 0; rndSpawn = 0; avgRadius = 0.0d; snapTol = 0.0d; snapAngle = 0.0d; windAngle = 0.0d; lineCont = false; surface = new GH_Surface(); bounds = new GH_Brep(); }
public static bool CastBrepTo <Q>(Rhino.Geometry.Brep brep, out Q target) { if (brep != null) { if (typeof(Q).IsAssignableFrom(typeof(GH_Brep))) { var gb = new GH_Brep(brep); target = (Q)(object)gb; return(true); } } target = default(Q); return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Brep brep = new GH_Brep(); DA.GetData <GH_Brep>("Element", ref brep); string layername = ""; Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc; if (brep.ReferenceID != null && brep.ReferenceID != Guid.Empty) { Rhino.DocObjects.RhinoObject obj = doc.Objects.Find(brep.ReferenceID); layername = doc.Layers[obj.Attributes.LayerIndex].Name; } DA.SetData("Layer", layername); }
public override List <SpeckleObjectProperties> getObjectProperties(IEnumerable <object> objects) { var propertiesList = new List <SpeckleObjectProperties>(); var simpleProps = new List <ArchivableDictionary>(); int k = 0; foreach (object o in objects) { CommonObject myObj = null; GH_Brep brep = o as GH_Brep; if (brep != null) { myObj = brep.Value; } GH_Surface srf = o as GH_Surface; if (srf != null) { myObj = srf.Value; } GH_Mesh mesh = o as GH_Mesh; if (mesh != null) { myObj = mesh.Value; } GH_Curve crv = o as GH_Curve; if (crv != null) { myObj = crv.Value; } if (myObj != null) { if (myObj.UserDictionary.Keys.Length > 0) { propertiesList.Add(new SpeckleObjectProperties(k, myObj.UserDictionary)); } } k++; } return(propertiesList); }
// we set up some defaults here to make it easier for the components // they will use these defaults if they are not passed a paramaters object public StaticSettings() { steps = 0; tolerance = 10.0d; stop = true; avgRadius = 0.0d; snapTol = 0.0d; snapAngle = 0.0d; windAngle = 0.0d; tensor = false; tensorDir = 0; lineCont = false; tensorAxes = new List <int>(new [] { 0, 1 }); surface = new GH_Surface(); bounds = new GH_Brep(); }
public static GH_Structure <GH_Brep> MakeTreeForBuildings(Dictionary <OSMTag, List <Brep> > foundBuildings) { var output = new GH_Structure <GH_Brep>(); var i = 0; foreach (var entry in foundBuildings) { for (int j = 0; j < entry.Value.Count; j++) { GH_Path path = new GH_Path(i, j); // Need to ensure even an empty path exists to enable data matching output.EnsurePath(path); // Need to ensure even an empty path exists to enable data matching GH_Brep brepForPath = new GH_Brep(entry.Value[j]); output.Append(brepForPath, path); } i++; } return(output); }
public override bool CastTo <Q>(out Q target) { if (Value != null) { if (typeof(Q).IsAssignableFrom(typeof(GH_Brep))) { var gb = new GH_Brep(this.Value); target = (Q)(object)gb; return(true); } else { throw new Exception("Unable to cast to type: " + typeof(Q).ToString()); } } target = default(Q); return(false); }
public static GH_Brep ProjectBrepToTopo(Mesh topoMesh, Brep brep) { GH_Brep ghBrep = new GH_Brep(); List <Mesh> topoMeshList = new List <Mesh>(); topoMeshList.Add(topoMesh); BoundingBox bb = brep.GetBoundingBox(false); ///Get list of verteces from mesh to project List <Point3d> originalVerts = new List <Point3d>(); foreach (var v in brep.Vertices) { originalVerts.Add(v.Location); } ///create a list of verteces who share the lowest Z value of the bounding box List <Point3d> lowestVerts = originalVerts.Where(lowPoint => lowPoint.Z == bb.Min.Z).ToList(); ///transalte mesh to project up with move vector and save to output array Vector3d moveV = GetMinProjectedPointToMesh(lowestVerts, topoMesh); Vector3d maxV = new Vector3d(0, 0, Double.MaxValue); if (moveV == maxV) { return(null); } brep.Translate(moveV); if (brep.IsValid) { GH_Convert.ToGHBrep(brep, GH_Conversion.Primary, ref ghBrep); return(ghBrep); } else { return(null); } }
protected override void BeforeSolveInstance() { ClearOutput(); point = false; curve = false; surface = false; brep = false; mesh = false; IGH_Structure dd = Params.Input[0].VolatileData; foreach (IGH_Goo geo in dd.AllData(true)) { if (geo is GH_Point) { point = true; } else if (geo is GH_Curve)////curve { curve = true; } else if (geo is GH_Brep) { GH_Brep bp = (GH_Brep)geo; if (bp.Value.IsSurface)///surface { surface = true; } else//////brep { brep = true; } } else if (geo is GH_Mesh) { mesh = true; GH_Mesh me = (GH_Mesh)geo; } } AddOutput(); }
protected override void SolveInstance(IGH_DataAccess DA) { Types.Assembly assembly = new Types.Assembly(); DA.GetData <Types.Assembly>("Material", ref assembly); GH_Brep brep = new GH_Brep(); GH_Number volume = new GH_Number(0); if (!DA.GetData <GH_Number>("Volume", ref volume)) { volume = new GH_Number(0); } if (!DA.GetData <GH_Brep>("Brep", ref brep)) { brep = new GH_Brep(); } double calculationVolume = volume.Value; if (brep.Value != null) { calculationVolume += brep.Value.GetVolume(); } Types.Result result = new Types.Result() { GlobalWarmingPotential = new Types.UnitDouble <Types.LCA.CO2e>(assembly.GlobalWarmingPotential.Value * calculationVolume), Acidification = new Types.UnitDouble <Types.LCA.kgSO2>(assembly.Acidification.Value * calculationVolume), DepletionOfNonrenewbles = new Types.UnitDouble <Types.LCA.MJ>(assembly.DepletionOfNonrenewbles.Value * calculationVolume), DepletionOfOzoneLayer = new Types.UnitDouble <Types.LCA.kgCFC11>(assembly.DepletionOfOzoneLayer.Value * calculationVolume), Eutrophication = new Types.UnitDouble <Types.LCA.kgPhostphate>(assembly.Eutrophication.Value * calculationVolume), FormationTroposphericOzone = new Types.UnitDouble <Types.LCA.kgNOx>(assembly.FormationTroposphericOzone.Value * calculationVolume) }; DA.SetData("LCA Result", result); }
public static string GrasshopperExport(Brep brep) { RhinoDoc.ActiveDoc.Objects.UnselectAll(); var gh_brep = new GH_Brep(brep); Guid brepGuid = Guid.Empty; gh_brep.BakeGeometry(RhinoDoc.ActiveDoc, new ObjectAttributes(), ref brepGuid); RhinoDoc.ActiveDoc.Objects.Select(brepGuid, true); string exportName = GetTempFileName("stp"); string exportCmd = "!_-Export _SaveSmall=Yes _GeometryOnly=Yes _SaveTextures=No _SavePlugInData=Yes " + "\"" + exportName + "\"" + " _Schema=AP214AutomotiveDesign _ExportParameterSpaceCurves=Yes _SplitClosedSurfaces=No _LetImportingApplicationSetColorForBlackObjects=Yes " + " _Enter"; RhinoApp.RunScript(exportCmd, false); RhinoDoc.ActiveDoc.Objects.Delete(brepGuid, true); return(exportName); }
public override bool CastTo <Q>(ref Q target) { if (typeof(Q).IsAssignableFrom(typeof(Feature))) { object blank = Value; target = (Q)blank; return(true); } else if (typeof(Q).IsAssignableFrom(typeof(GH_Brep))) { object blank = new GH_Brep(Value.ToBrep()); target = (Q)blank; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Curve))) { object cl = new GH_Curve(Value.ToNurbsCurve()); target = (Q)cl; return(true); } return(base.CastTo <Q>(ref target)); }
//public static implicit operator Glulam(GH_Glulam g) => g.Value; //public static implicit operator GH_Glulam(Glulam g) => new GH_Glulam(g); public override bool CastTo <Q>(ref Q target) { if (Value == null) { return(false); } if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh))) { object mesh = new GH_Mesh(Value.GetBoundingMesh()); target = (Q)mesh; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Brep))) { object blank = new GH_Brep(Value.GetBoundingBrep()); target = (Q)blank; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Curve))) { object cl = new GH_Curve(Value.Centreline); target = (Q)cl; return(true); } if (typeof(Q).IsAssignableFrom(typeof(Lam.Glulam))) { object blank = Value; target = (Q)blank; return(true); } return(false); }
public override bool CastTo <Q>(ref Q target) { if (typeof(Q).IsAssignableFrom(typeof(GH_Mesh))) { Mesh[] meshes = Value.ToMesh(); Mesh m = new Mesh(); for (int i = 0; i < meshes.Length; ++i) { m.Append(meshes[i]); } object mesh = new GH_Mesh(m); target = (Q)mesh; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GlulamAssembly))) { object blank = Value; target = (Q)blank; return(true); } if (typeof(Q).IsAssignableFrom(typeof(GH_Brep))) { Brep[] breps = Value.ToBrep(); Brep b = new Brep(); for (int i = 0; i < breps.Length; ++i) { b.Append(breps[i]); } object brep = new GH_Brep(b); target = (Q)brep; return(true); } return(base.CastTo <Q>(ref target)); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { #region INPUTS // import silkwormSettings file List<string> silkwormSettings = new List<string>(); if (!DA.GetDataList(0, silkwormSettings)) return; List<GH_ObjectWrapper> things = new List<GH_ObjectWrapper>(); if (!DA.GetDataList(1, things)) return; // import Silkworm Movement #endregion SilkwormUtility sUtil = new SilkwormUtility(); Dictionary<string, string> Settings = sUtil.convertSettings(silkwormSettings); #region Optional Variables int shell = -999; if (!DA.GetData(4, ref shell)) { } double layerheight = -999; if (!DA.GetData(3, ref layerheight)) { } //bool detect = false; //if (!DA.GetData(5, ref detect)) { } List<Plane> sliceplanes = new List<Plane>(); if (!DA.GetDataList(2, sliceplanes)) { } if (shell == -999) { shell = int.Parse(Settings["perimeters"]); } if (layerheight == -999) { layerheight = double.Parse(Settings["layer_height"]); } if (sliceplanes.Count<1) { sliceplanes.Add(Plane.WorldXY); } #endregion List<Brep> Breps = new List<Brep>(); List<Mesh> Meshes = new List<Mesh>(); SilkwormSkein skein = new SilkwormSkein(); #region Sort Types foreach (GH_ObjectWrapper obj in things) { if (obj.Value is GH_Brep) { Brep brep = null; GH_Convert.ToBrep(obj.Value, ref brep, GH_Conversion.Both); Breps.Add(brep); continue; } if (obj.Value is GH_Mesh) { Mesh mesh = null; GH_Convert.ToMesh(obj.Value, ref mesh, GH_Conversion.Both); Meshes.Add(mesh); continue; } } #endregion if (Breps.Count>0) { skein = new SilkwormSkein(Settings, Breps, sliceplanes, shell, layerheight); skein.BrepSlice(false); } if (Meshes.Count > 0) { //TODO } //Reflect Errors and Warnings foreach (string message in skein.ErrorMessages) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message); } foreach (string message in skein.WarningMessages) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, message); } List<Curve>[] openregions = skein.openRegions; List<Brep>[] rRegions = skein.Regions; List<Brep>[] rPerimeterR = skein.regionPerimeter; List<Brep>[] rInfillR = skein.regionInfill; GH_Structure<GH_Brep> Regions = new GH_Structure<GH_Brep>(); GH_Structure<GH_Curve> openRegions = new GH_Structure<GH_Curve>(); #region Add Regions to GH_Structure if (rRegions.GetUpperBound(0) > 1) { for (int i = 0; i < rRegions.Length; i++) { if (rRegions[i] != null) { for (int j = 0; j < rRegions[i].Count; j++) { GH_Brep gShapes = new GH_Brep(rRegions[i][j]); Regions.Insert(gShapes, new GH_Path(i, 0), j); } } } } if (rPerimeterR.GetUpperBound(0) > 1) { for (int i = 0; i < rPerimeterR.Length; i++) { if (rPerimeterR[i] != null) { for (int j = 0; j < rPerimeterR[i].Count; j++) { GH_Brep gShapes = new GH_Brep(rPerimeterR[i][j]); Regions.Insert(gShapes, new GH_Path(i, 1), j); } } } } if (rInfillR.GetUpperBound(0) > 1) { for (int i = 0; i < rInfillR.Length; i++) { if (rInfillR[i] != null) { for (int j = 0; j < rInfillR[i].Count; j++) { GH_Brep gShapes = new GH_Brep(rInfillR[i][j]); Regions.Insert(gShapes, new GH_Path(i, 2), j); } } } } if (openregions.GetUpperBound(0) > 1) { for (int i = 0; i < openregions.Length; i++) { if (openregions[i] != null) { for (int j = 0; j < openregions[i].Count; j++) { GH_Curve gShapes = new GH_Curve(openregions[i][j]); openRegions.Insert(gShapes, new GH_Path(i), j); } } } } //TODO //Add Overhang and Bridges #endregion #region Add Open Regions to GH_Structure if (openregions.GetUpperBound(0) > 1) { for (int i = 0; i < openregions.Length; i++) { for (int j = 0; j < openregions[i].Count; j++) { if (openregions[i][j] != null) { SilkwormSegment segment = new SilkwormSegment(openregions[i][j]); Curve curve = segment.Pline.ToNurbsCurve(); GH_Curve gShapes = new GH_Curve(curve); openRegions.Insert(gShapes, new GH_Path(i), j); } } } } #endregion #region OUTPUT if (!DA.SetDataTree(0, Regions)) { return; } if (!DA.SetDataTree(1, openRegions)) { return; } #endregion }
public void SetInputs(List <DataTree <ResthopperObject> > values) { foreach (var tree in values) { if (!_input.TryGetValue(tree.ParamName, out var inputGroup)) { continue; } if (inputGroup.AlreadySet(tree)) { Console.WriteLine("Skipping input tree... same input"); continue; } inputGroup.CacheTree(tree); inputGroup.Param.VolatileData.Clear(); inputGroup.Param.ExpireSolution(true); if (inputGroup.Param is Param_Point) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Point3d rPt = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); GH_Point data = new GH_Point(rPt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Vector) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data); GH_Vector data = new GH_Vector(rhVector); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Integer) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; int rhinoInt = JsonConvert.DeserializeObject <int>(restobj.Data); GH_Integer data = new GH_Integer(rhinoInt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Number) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_String) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = restobj.Data; GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Line) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Line rhLine = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); GH_Line data = new GH_Line(rhLine); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Curve) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; GH_Curve ghCurve; try { Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.PolylineCurve(data); ghCurve = new GH_Curve(c); } catch { var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data); var c = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict); ghCurve = new GH_Curve(c); } inputGroup.Param.AddVolatileData(path, i, ghCurve); } } continue; } if (inputGroup.Param is Param_Circle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data); GH_Circle data = new GH_Circle(rhCircle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Plane) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data); GH_Plane data = new GH_Plane(rhPlane); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Rectangle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data); GH_Rectangle data = new GH_Rectangle(rhRectangle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Box) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Box rhBox = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data); GH_Box data = new GH_Box(rhBox); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Surface) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data); GH_Surface data = new GH_Surface(rhSurface); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Brep) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Brep rhBrep = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data); GH_Brep data = new GH_Brep(rhBrep); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Mesh) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Mesh rhMesh = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data); GH_Mesh data = new GH_Mesh(rhMesh); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_NumberSlider) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool boolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(boolean); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_Panel) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } } }
protected override void SolveInstance(IGH_DataAccess DA) { Types.Assembly assembly = new Types.Assembly(); DA.GetData<Types.Assembly>("Material", ref assembly); GH_Brep brep = new GH_Brep(); GH_Number volume = new GH_Number(0); if (!DA.GetData<GH_Number>("Volume", ref volume)) volume = new GH_Number(0); if (!DA.GetData<GH_Brep>("Brep", ref brep)) brep = new GH_Brep(); double calculationVolume = volume.Value; if (brep.Value != null) calculationVolume += brep.Value.GetVolume(); Types.Result result = new Types.Result() { GlobalWarmingPotential = new Types.UnitDouble<Types.LCA.CO2e>(assembly.GlobalWarmingPotential.Value * calculationVolume), Acidification = new Types.UnitDouble<Types.LCA.kgSO2>(assembly.Acidification.Value * calculationVolume), DepletionOfNonrenewbles = new Types.UnitDouble<Types.LCA.MJ>(assembly.DepletionOfNonrenewbles.Value * calculationVolume), DepletionOfOzoneLayer = new Types.UnitDouble<Types.LCA.kgCFC11>(assembly.DepletionOfOzoneLayer.Value * calculationVolume), Eutrophication = new Types.UnitDouble<Types.LCA.kgPhostphate>(assembly.Eutrophication.Value * calculationVolume), FormationTroposphericOzone = new Types.UnitDouble<Types.LCA.kgNOx>(assembly.FormationTroposphericOzone.Value * calculationVolume) }; DA.SetData("LCA Result", result); }
// SOLVER // Retrieves data from Grasshopper and changes component properties that can be accessed in the code-behind of stormcloud.xaml protected override void SolveInstance(IGH_DataAccess DA) { //// GEOMETRY //// Use IGH_GeometricGoo to deal with different geometry types List <IGH_GeometricGoo> g = new List <IGH_GeometricGoo>(); if (!DA.GetDataList <IGH_GeometricGoo>(0, g)) { return; } // retrieves list of geometries as list of IGH_GeometricGoo List <Curve> curves = new List <Curve>(); List <Mesh> meshes = new List <Mesh>(); List <Brep> breps = new List <Brep>(); foreach (IGH_GeometricGoo goo in g) { GH_Line l = goo as GH_Line; if (l != null) { GH_Curve lc = new GH_Curve(); l.CastTo <GH_Curve>(out lc); curves.Add(lc.DuplicateCurve().Value); } GH_Curve c = goo as GH_Curve; // c = null if geometry is not a curve if (c != null) { curves.Add(c.DuplicateCurve().Value); // add to curves if geometry is a curve Console.WriteLine("There is a Curve"); } GH_Mesh m = goo as GH_Mesh; if (m != null) { GH_Brep br = new GH_Brep(); m.CastTo <GH_Brep>(out br); breps.Add(br.DuplicateBrep().Value); } //GH_Surface s = goo as GH_Surface; //if (s != null) //{ // GH_Brep brs = new GH_Brep(); // s.CastTo<GH_Brep>(out brs); // breps.Add(brs.DuplicateBrep().Value); //} GH_Brep b = goo as GH_Brep; if (b != null) { breps.Add(b.DuplicateBrep().Value); } } //// Change values of relevant component properties DesignCurves = curves; DesignMeshes = meshes; DesignBreps = breps; // DesignLines //List<Line> lines = new List<Line>(); //if (!DA.GetDataList(0, lines)) { return; } //DesignLines = lines; // SCORE double score = 0; // instantiate score if (!DA.GetData(1, ref score)) { return; } Score = score; // Change value of component property // Update model of main 3D viewports in stormcloud if (this.DesignView.InitialDesign.Score != 0) { DesignView.UpdateCurrentScore(Score); } else { DesignView.UpdateCurrentScore(1.00); } //DesignView.UpdateCurrentModel(DesignLines, RenderingSettings.diameter, RenderingSettings.resolutiontube, RenderingSettings.mat); DesignView.UpdateCurrentModelAdvanced(DesignCurves, DesignMeshes, DesignBreps, RenderingSettings.diameter, RenderingSettings.resolution, RenderingSettings.resolutiontube, RenderingSettings.mat); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { Object ghGeometryBase = null; double tolerance = 0.0001; if (!DA.GetData(0, ref ghGeometryBase)) { return; } if (!DA.GetData(1, ref tolerance)) { return; } if (ghGeometryBase == null) { return; } Type type = ghGeometryBase.GetType(); Topologic.Topology topology = null; GH_Point ghPoint = ghGeometryBase as GH_Point; if (ghPoint != null) { topology = ByPoint(ghPoint.Value); DA.SetData(0, topology); return; } GH_Line ghLine = ghGeometryBase as GH_Line; if (ghLine != null) { topology = ByLine(ghLine.Value); DA.SetData(0, topology); return; } GH_Curve ghCurve = ghGeometryBase as GH_Curve; if (ghCurve != null) { topology = ByCurve(ghCurve.Value); DA.SetData(0, topology); return; } GH_Surface ghSurface = ghGeometryBase as GH_Surface; if (ghSurface != null) { //topology = ByBrep(ghSurface.Value.Faces[0].ToBrep(), tolerance); //topology = ByBrepFace(ghSurface.Value.Faces[0]); topology = ByBrep(ghSurface.Value, tolerance); DA.SetData(0, topology); return; } GH_Brep ghBrep = ghGeometryBase as GH_Brep; if (ghBrep != null) { topology = ByBrep(ghBrep.Value, tolerance); DA.SetData(0, topology); return; } GH_Box ghBox = ghGeometryBase as GH_Box; if (ghBox != null) { topology = ByBox(ghBox.Value); DA.SetData(0, topology); return; } GH_Mesh ghMesh = ghGeometryBase as GH_Mesh; if (ghMesh != null) { topology = ByMesh(ghMesh.Value); DA.SetData(0, topology); return; } //BrepLoop ghBrepLoop = ghGeometryBase as BrepLoop; //if (ghBrepLoop != null) //{ // topology = ByBrepLoop(ghBrepLoop); // DA.SetData(0, topology); // return; //} throw new Exception("This type of geometry is not yet supported."); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { #region INPUTS // import silkwormSettings file List <string> silkwormSettings = new List <string>(); if (!DA.GetDataList(0, silkwormSettings)) { return; } List <GH_ObjectWrapper> things = new List <GH_ObjectWrapper>(); if (!DA.GetDataList(1, things)) { return; } // import Silkworm Movement #endregion SilkwormUtility sUtil = new SilkwormUtility(); Dictionary <string, string> Settings = sUtil.convertSettings(silkwormSettings); #region Optional Variables int shell = -999; if (!DA.GetData(4, ref shell)) { } double layerheight = -999; if (!DA.GetData(3, ref layerheight)) { } //bool detect = false; //if (!DA.GetData(5, ref detect)) { } List <Plane> sliceplanes = new List <Plane>(); if (!DA.GetDataList(2, sliceplanes)) { } if (shell == -999) { shell = int.Parse(Settings["perimeters"]); } if (layerheight == -999) { layerheight = double.Parse(Settings["layer_height"]); } if (sliceplanes.Count < 1) { sliceplanes.Add(Plane.WorldXY); } #endregion List <Brep> Breps = new List <Brep>(); List <Mesh> Meshes = new List <Mesh>(); SilkwormSkein skein = new SilkwormSkein(); #region Sort Types foreach (GH_ObjectWrapper obj in things) { if (obj.Value is GH_Brep) { Brep brep = null; GH_Convert.ToBrep(obj.Value, ref brep, GH_Conversion.Both); Breps.Add(brep); continue; } if (obj.Value is GH_Mesh) { Mesh mesh = null; GH_Convert.ToMesh(obj.Value, ref mesh, GH_Conversion.Both); Meshes.Add(mesh); continue; } } #endregion if (Breps.Count > 0) { skein = new SilkwormSkein(Settings, Breps, sliceplanes, shell, layerheight); skein.BrepSlice(false); } if (Meshes.Count > 0) { //TODO } //Reflect Errors and Warnings foreach (string message in skein.ErrorMessages) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, message); } foreach (string message in skein.WarningMessages) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, message); } List <Curve>[] openregions = skein.openRegions; List <Brep>[] rRegions = skein.Regions; List <Brep>[] rPerimeterR = skein.regionPerimeter; List <Brep>[] rInfillR = skein.regionInfill; GH_Structure <GH_Brep> Regions = new GH_Structure <GH_Brep>(); GH_Structure <GH_Curve> openRegions = new GH_Structure <GH_Curve>(); #region Add Regions to GH_Structure if (rRegions.GetUpperBound(0) > 1) { for (int i = 0; i < rRegions.Length; i++) { if (rRegions[i] != null) { for (int j = 0; j < rRegions[i].Count; j++) { GH_Brep gShapes = new GH_Brep(rRegions[i][j]); Regions.Insert(gShapes, new GH_Path(i, 0), j); } } } } if (rPerimeterR.GetUpperBound(0) > 1) { for (int i = 0; i < rPerimeterR.Length; i++) { if (rPerimeterR[i] != null) { for (int j = 0; j < rPerimeterR[i].Count; j++) { GH_Brep gShapes = new GH_Brep(rPerimeterR[i][j]); Regions.Insert(gShapes, new GH_Path(i, 1), j); } } } } if (rInfillR.GetUpperBound(0) > 1) { for (int i = 0; i < rInfillR.Length; i++) { if (rInfillR[i] != null) { for (int j = 0; j < rInfillR[i].Count; j++) { GH_Brep gShapes = new GH_Brep(rInfillR[i][j]); Regions.Insert(gShapes, new GH_Path(i, 2), j); } } } } if (openregions.GetUpperBound(0) > 1) { for (int i = 0; i < openregions.Length; i++) { if (openregions[i] != null) { for (int j = 0; j < openregions[i].Count; j++) { GH_Curve gShapes = new GH_Curve(openregions[i][j]); openRegions.Insert(gShapes, new GH_Path(i), j); } } } } //TODO //Add Overhang and Bridges #endregion #region Add Open Regions to GH_Structure if (openregions.GetUpperBound(0) > 1) { for (int i = 0; i < openregions.Length; i++) { for (int j = 0; j < openregions[i].Count; j++) { if (openregions[i][j] != null) { SilkwormSegment segment = new SilkwormSegment(openregions[i][j]); Curve curve = segment.Pline.ToNurbsCurve(); GH_Curve gShapes = new GH_Curve(curve); openRegions.Insert(gShapes, new GH_Path(i), j); } } } } #endregion #region OUTPUT if (!DA.SetDataTree(0, Regions)) { return; } if (!DA.SetDataTree(1, openRegions)) { return; } #endregion }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { GH_Structure <GH_Brep> sBreps = new GH_Structure <GH_Brep>(); DA.GetDataTree <GH_Brep>(0, out sBreps); GH_Structure <GH_Brep> dBreps = new GH_Structure <GH_Brep>(); DA.GetDataTree <GH_Brep>(1, out dBreps); double tol = DocumentTolerance(); ///Reserve one processor for GUI int totalMaxConcurrancy = System.Environment.ProcessorCount - 1; ///Tells us how many threads were using Message = totalMaxConcurrancy + " threads"; ///Declare dictionaries that work in parallel to hold the successful boolean results and ///the unsuccessful boolean cutters var mainBrepsMT = new System.Collections.Concurrent.ConcurrentDictionary <GH_Path, GH_Brep>(); var badBrepsMT = new System.Collections.Concurrent.ConcurrentDictionary <GH_Path, List <GH_Brep> >(); ///Start of the parallel engine ///Cast to GH_Brep to Brep and back in parallel engine to avoid speed hit when casting all at once later System.Threading.Tasks.Parallel.ForEach(sBreps.Paths, new System.Threading.Tasks.ParallelOptions { MaxDegreeOfParallelism = totalMaxConcurrancy }, pth => { List <GH_Brep> badBrep = new List <GH_Brep>(); Brep mainBrep = new Brep(); GH_Convert.ToBrep(sBreps.get_Branch(pth)[0], ref mainBrep, 0); List <Brep> diffBreps = new List <Brep>(); foreach (var d_GH in dBreps.get_Branch(pth)) { Brep d_Rhino = new Brep(); GH_Convert.ToBrep(d_GH, ref d_Rhino, 0); diffBreps.Add(d_Rhino); } ///Difference one cutter brep at a time from the main brep in the branch. ///This allows the boolean operation to continue without failing ///and bad cutter breps can be discarded to a list that can be used for troubleshooting ///haven't noticed a hit big hit on performance foreach (Brep b in diffBreps) { Brep[] breps = new Brep[] { }; breps = Brep.CreateBooleanDifference(mainBrep, b, tol); if ((breps == null) || (breps.Length < 1)) { badBrep.Add(new GH_Brep(b)); } else { mainBrep = breps[0]; } } mainBrepsMT[pth] = new GH_Brep(mainBrep); badBrepsMT[pth] = badBrep; }); ///End of the parallel engine /// //convert dictionaries to regular old data trees GH_Structure <GH_Brep> mainBreps = new GH_Structure <GH_Brep>(); GH_Structure <GH_Brep> badBreps = new GH_Structure <GH_Brep>(); foreach (KeyValuePair <GH_Path, GH_Brep> p in mainBrepsMT) { mainBreps.Append(p.Value, p.Key); } foreach (KeyValuePair <GH_Path, List <GH_Brep> > b in badBrepsMT) { badBreps.AppendRange(b.Value, b.Key); } DA.SetDataTree(0, mainBreps); DA.SetDataTree(1, badBreps); }
public void SetInputs(List <DataTree <ResthopperObject> > values) { foreach (var tree in values) { if (!_input.TryGetValue(tree.ParamName, out var inputGroup)) { continue; } if (inputGroup.AlreadySet(tree)) { LogDebug("Skipping input tree... same input"); continue; } inputGroup.CacheTree(tree); IGH_ContextualParameter contextualParameter = inputGroup.Param as IGH_ContextualParameter; if (contextualParameter != null) { switch (ParamTypeName(inputGroup.Param)) { case "Number": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { double[] doubles = new double[entree.Value.Count]; for (int i = 0; i < doubles.Length; i++) { ResthopperObject restobj = entree.Value[i]; doubles[i] = JsonConvert.DeserializeObject <double>(restobj.Data); } contextualParameter.AssignContextualData(doubles); break; } } break; case "Integer": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { int[] integers = new int[entree.Value.Count]; for (int i = 0; i < integers.Length; i++) { ResthopperObject restobj = entree.Value[i]; integers[i] = JsonConvert.DeserializeObject <int>(restobj.Data); } contextualParameter.AssignContextualData(integers); break; } } break; case "Point": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { Point3d[] points = new Point3d[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; points[i] = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); } contextualParameter.AssignContextualData(points); break; } } break; case "Line": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { Line[] lines = new Line[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; lines[i] = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); } contextualParameter.AssignContextualData(lines); break; } } break; case "Text": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { string[] strings = new string[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; strings[i] = restobj.Data.Trim(new char[] { '"' }); } contextualParameter.AssignContextualData(strings); break; } } break; case "Geometry": { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GeometryBase[] geometries = new GeometryBase[entree.Value.Count]; for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data); geometries[i] = Rhino.Runtime.CommonObject.FromJSON(dict) as GeometryBase; } contextualParameter.AssignContextualData(geometries); break; } } break; } continue; } inputGroup.Param.VolatileData.Clear(); inputGroup.Param.ExpireSolution(false); // mark param as expired but don't recompute just yet! if (inputGroup.Param is Param_Point) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Point3d rPt = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); GH_Point data = new GH_Point(rPt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Vector) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data); GH_Vector data = new GH_Vector(rhVector); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Integer) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; int rhinoInt = JsonConvert.DeserializeObject <int>(restobj.Data); GH_Integer data = new GH_Integer(rhinoInt); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Number) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_String) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = restobj.Data; GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Line) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Line rhLine = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); GH_Line data = new GH_Line(rhLine); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Curve) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; GH_Curve ghCurve; try { Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.PolylineCurve(data); ghCurve = new GH_Curve(c); } catch { var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data); var c = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict); ghCurve = new GH_Curve(c); } inputGroup.Param.AddVolatileData(path, i, ghCurve); } } continue; } if (inputGroup.Param is Param_Circle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data); GH_Circle data = new GH_Circle(rhCircle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Plane) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data); GH_Plane data = new GH_Plane(rhPlane); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Rectangle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data); GH_Rectangle data = new GH_Rectangle(rhRectangle); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Box) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Box rhBox = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data); GH_Box data = new GH_Box(rhBox); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Surface) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data); GH_Surface data = new GH_Surface(rhSurface); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Brep) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Brep rhBrep = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data); GH_Brep data = new GH_Brep(rhBrep); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Mesh) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Mesh rhMesh = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data); GH_Mesh data = new GH_Mesh(rhMesh); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_NumberSlider) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool boolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(boolean); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } if (inputGroup.Param is GH_Panel) { foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); inputGroup.Param.AddVolatileData(path, i, data); } } continue; } } }
public static Response Grasshopper(NancyContext ctx) { // load grasshopper file var archive = new GH_Archive(); // TODO: stream to string var body = ctx.Request.Body.ToString(); string json = string.Empty; using (var reader = new StreamReader(ctx.Request.Body)) { json = reader.ReadToEnd(); } //GrasshopperInput input = Newtonsoft.Json.JsonConvert.DeserializeObject<GrasshopperInput>(json); //JsonSerializerSettings settings = new JsonSerializerSettings(); //settings.ContractResolver = new DictionaryAsArrayResolver(); Schema input = JsonConvert.DeserializeObject <Schema>(json); string grasshopperXml = string.Empty; if (input.Algo != null) { // If request contains markup byte[] byteArray = Convert.FromBase64String(input.Algo); grasshopperXml = System.Text.Encoding.UTF8.GetString(byteArray); } else { // If request contains pointer string pointer = input.Pointer; grasshopperXml = GetGhxFromPointer(pointer); } if (!archive.Deserialize_Xml(grasshopperXml)) { throw new Exception(); } var definition = new GH_Document(); if (!archive.ExtractObject(definition, "Definition")) { throw new Exception(); } // Set input params foreach (var obj in definition.Objects) { var group = obj as GH_Group; if (group == null) { continue; } if (group.NickName.Contains("RH_IN")) { // It is a RestHopper input group! GHTypeCodes code = (GHTypeCodes)Int32.Parse(group.NickName.Split(':')[1]); var param = group.Objects()[0]; //GH_Param<IGH_Goo> goo = obj as GH_Param<IGH_Goo>; // SetData foreach (Resthopper.IO.DataTree <ResthopperObject> tree in input.Values) { string paramname = tree.ParamName; if (group.NickName == paramname) { switch (code) { case GHTypeCodes.Boolean: //PopulateParam<GH_Boolean>(goo, tree); Param_Boolean boolParam = param as Param_Boolean; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Boolean> objectList = new List <GH_Boolean>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool boolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(boolean); boolParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Point: //PopulateParam<GH_Point>(goo, tree); Param_Point ptParam = param as Param_Point; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Point> objectList = new List <GH_Point>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Point3d rPt = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data); GH_Point data = new GH_Point(rPt); ptParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Vector: //PopulateParam<GH_Vector>(goo, tree); Param_Vector vectorParam = param as Param_Vector; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Vector> objectList = new List <GH_Vector>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data); GH_Vector data = new GH_Vector(rhVector); vectorParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Integer: //PopulateParam<GH_Integer>(goo, tree); Param_Integer integerParam = param as Param_Integer; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Integer> objectList = new List <GH_Integer>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; int rhinoInt = JsonConvert.DeserializeObject <int>(restobj.Data); GH_Integer data = new GH_Integer(rhinoInt); integerParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Number: //PopulateParam<GH_Number>(goo, tree); Param_Number numberParam = param as Param_Number; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Number> objectList = new List <GH_Number>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); numberParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Text: //PopulateParam<GH_String>(goo, tree); Param_String stringParam = param as Param_String; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_String> objectList = new List <GH_String>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); stringParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Line: //PopulateParam<GH_Line>(goo, tree); Param_Line lineParam = param as Param_Line; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Line> objectList = new List <GH_Line>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Line rhLine = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data); GH_Line data = new GH_Line(rhLine); lineParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Curve: //PopulateParam<GH_Curve>(goo, tree); Param_Curve curveParam = param as Param_Curve; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Curve> objectList = new List <GH_Curve>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; GH_Curve ghCurve; try { Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.PolylineCurve(data); ghCurve = new GH_Curve(c); } catch { Rhino.Geometry.NurbsCurve data = JsonConvert.DeserializeObject <Rhino.Geometry.NurbsCurve>(restobj.Data); Rhino.Geometry.Curve c = new Rhino.Geometry.NurbsCurve(data); ghCurve = new GH_Curve(c); } curveParam.AddVolatileData(path, i, ghCurve); } } break; case GHTypeCodes.Circle: //PopulateParam<GH_Circle>(goo, tree); Param_Circle circleParam = param as Param_Circle; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Circle> objectList = new List <GH_Circle>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data); GH_Circle data = new GH_Circle(rhCircle); circleParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.PLane: //PopulateParam<GH_Plane>(goo, tree); Param_Plane planeParam = param as Param_Plane; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Plane> objectList = new List <GH_Plane>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data); GH_Plane data = new GH_Plane(rhPlane); planeParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Rectangle: //PopulateParam<GH_Rectangle>(goo, tree); Param_Rectangle rectangleParam = param as Param_Rectangle; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Rectangle> objectList = new List <GH_Rectangle>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data); GH_Rectangle data = new GH_Rectangle(rhRectangle); rectangleParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Box: //PopulateParam<GH_Box>(goo, tree); Param_Box boxParam = param as Param_Box; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Box> objectList = new List <GH_Box>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Box rhBox = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data); GH_Box data = new GH_Box(rhBox); boxParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Surface: //PopulateParam<GH_Surface>(goo, tree); Param_Surface surfaceParam = param as Param_Surface; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Surface> objectList = new List <GH_Surface>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data); GH_Surface data = new GH_Surface(rhSurface); surfaceParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Brep: //PopulateParam<GH_Brep>(goo, tree); Param_Brep brepParam = param as Param_Brep; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Brep> objectList = new List <GH_Brep>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Brep rhBrep = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data); GH_Brep data = new GH_Brep(rhBrep); brepParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Mesh: //PopulateParam<GH_Mesh>(goo, tree); Param_Mesh meshParam = param as Param_Mesh; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Mesh> objectList = new List <GH_Mesh>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; Rhino.Geometry.Mesh rhMesh = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data); GH_Mesh data = new GH_Mesh(rhMesh); meshParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Slider: //PopulateParam<GH_Number>(goo, tree); GH_NumberSlider sliderParam = param as GH_NumberSlider; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Number> objectList = new List <GH_Number>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; double rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data); GH_Number data = new GH_Number(rhNumber); sliderParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.BooleanToggle: //PopulateParam<GH_Boolean>(goo, tree); GH_BooleanToggle toggleParam = param as GH_BooleanToggle; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Boolean> objectList = new List <GH_Boolean>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; bool rhBoolean = JsonConvert.DeserializeObject <bool>(restobj.Data); GH_Boolean data = new GH_Boolean(rhBoolean); toggleParam.AddVolatileData(path, i, data); } } break; case GHTypeCodes.Panel: //PopulateParam<GH_String>(goo, tree); GH_Panel panelParam = param as GH_Panel; foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree) { GH_Path path = new GH_Path(GhPath.FromString(entree.Key)); List <GH_Panel> objectList = new List <GH_Panel>(); for (int i = 0; i < entree.Value.Count; i++) { ResthopperObject restobj = entree.Value[i]; string rhString = JsonConvert.DeserializeObject <string>(restobj.Data); GH_String data = new GH_String(rhString); panelParam.AddVolatileData(path, i, data); } } break; } } } } } Schema OutputSchema = new Schema(); OutputSchema.Algo = Utils.Base64Encode(string.Empty); // Parse output params foreach (var obj in definition.Objects) { var group = obj as GH_Group; if (group == null) { continue; } if (group.NickName.Contains("RH_OUT")) { // It is a RestHopper output group! GHTypeCodes code = (GHTypeCodes)Int32.Parse(group.NickName.Split(':')[1]); var param = group.Objects()[0] as IGH_Param; if (param == null) { continue; } try { param.CollectData(); param.ComputeData(); } catch (Exception) { param.Phase = GH_SolutionPhase.Failed; // TODO: throw something better throw; } // Get data Resthopper.IO.DataTree <ResthopperObject> OutputTree = new Resthopper.IO.DataTree <ResthopperObject>(); OutputTree.ParamName = group.NickName; var volatileData = param.VolatileData; for (int p = 0; p < volatileData.PathCount; p++) { List <ResthopperObject> ResthopperObjectList = new List <ResthopperObject>(); foreach (var goo in volatileData.get_Branch(p)) { if (goo == null) { continue; } else if (goo.GetType() == typeof(GH_Boolean)) { GH_Boolean ghValue = goo as GH_Boolean; bool rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <bool>(rhValue)); } else if (goo.GetType() == typeof(GH_Point)) { GH_Point ghValue = goo as GH_Point; Point3d rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Point3d>(rhValue)); } else if (goo.GetType() == typeof(GH_Vector)) { GH_Vector ghValue = goo as GH_Vector; Vector3d rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Vector3d>(rhValue)); } else if (goo.GetType() == typeof(GH_Integer)) { GH_Integer ghValue = goo as GH_Integer; int rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <int>(rhValue)); } else if (goo.GetType() == typeof(GH_Number)) { GH_Number ghValue = goo as GH_Number; double rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <double>(rhValue)); } else if (goo.GetType() == typeof(GH_String)) { GH_String ghValue = goo as GH_String; string rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <string>(rhValue)); } else if (goo.GetType() == typeof(GH_Line)) { GH_Line ghValue = goo as GH_Line; Line rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Line>(rhValue)); } else if (goo.GetType() == typeof(GH_Curve)) { GH_Curve ghValue = goo as GH_Curve; Curve rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Curve>(rhValue)); } else if (goo.GetType() == typeof(GH_Circle)) { GH_Circle ghValue = goo as GH_Circle; Circle rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Circle>(rhValue)); } else if (goo.GetType() == typeof(GH_Plane)) { GH_Plane ghValue = goo as GH_Plane; Plane rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Plane>(rhValue)); } else if (goo.GetType() == typeof(GH_Rectangle)) { GH_Rectangle ghValue = goo as GH_Rectangle; Rectangle3d rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Rectangle3d>(rhValue)); } else if (goo.GetType() == typeof(GH_Box)) { GH_Box ghValue = goo as GH_Box; Box rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Box>(rhValue)); } else if (goo.GetType() == typeof(GH_Surface)) { GH_Surface ghValue = goo as GH_Surface; Brep rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Brep>(rhValue)); } else if (goo.GetType() == typeof(GH_Brep)) { GH_Brep ghValue = goo as GH_Brep; Brep rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Brep>(rhValue)); } else if (goo.GetType() == typeof(GH_Mesh)) { GH_Mesh ghValue = goo as GH_Mesh; Mesh rhValue = ghValue.Value; ResthopperObjectList.Add(GetResthopperObject <Mesh>(rhValue)); } } GhPath path = new GhPath(new int[] { p }); OutputTree.Add(path.ToString(), ResthopperObjectList); } OutputSchema.Values.Add(OutputTree); } } if (OutputSchema.Values.Count < 1) { throw new System.Exceptions.PayAttentionException("Looks like you've missed something..."); // TODO } string returnJson = JsonConvert.SerializeObject(OutputSchema); return(returnJson); }