public ArchivableDictionary GlulamPropertiesToArchivableDictionary(Glulam g) { ArchivableDictionary ad = new ArchivableDictionary(); var gd = g.GetProperties(); //ad.Set("id", g.ID); ad.Set("centreline", g.Centreline); ad.Set("width", g.Width); ad.Set("height", g.Height); ad.Set("lamella_width", g.Data.LamWidth); ad.Set("lamella_height", g.Data.LamHeight); ad.Set("lamella_count_width", g.Data.NumWidth); ad.Set("lamella_count_height", g.Data.NumHeight); ad.Set("volume", g.GetVolume()); ad.Set("samples", g.Data.Samples); /* * var planes = g.GetAllPlanes(); * ArchivableDictionary pd = new ArchivableDictionary(); * * for (int i = 0; i < planes.Length; ++i) * { * pd.Set(string.Format("Frame_{0}", i), planes[i]); * } * ad.Set("frames", pd); * */ double max_kw = 0.0, max_kh = 0.0; ad.Set("max_curvature", g.GetMaxCurvature(ref max_kw, ref max_kh)); ad.Set("max_curvature_width", max_kw); ad.Set("max_curvature_height", max_kh); ad.Set("type", g.ToString()); ad.Set("type_id", (int)g.Type()); return(ad); }
protected override void SolveInstance(IGH_DataAccess DA) { Glulam g = null; if (!DA.GetData <Glulam>("Glulam", ref g)) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No glulam blank connected."); return; } List <string> keys = new List <string>(); if (!DA.GetDataList("Key", keys)) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No keys found."); return; } /* * Glulam g; * * if (obj is GH_Glulam) * g = (obj as GH_Glulam).Value; * else * g = obj as Glulam; * * if (g == null) * { * AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid glulam input."); * return; * } */ DataTree <object> output = new DataTree <object>(); Dictionary <string, object> props = g.GetProperties(); for (int i = 0; i < keys.Count; ++i) { if (props.ContainsKey(keys[i])) { if (props[keys[i]].GetType().IsArray) { Type t = props[keys[i]].GetType().GetElementType(); if (t == typeof(Rhino.Geometry.Plane)) { var ar = props[keys[i]] as Rhino.Geometry.Plane[]; GH_Path path = new GH_Path(i); for (int j = 0; j < ar.Length; ++j) { output.Add(ar[j], path); } } } else { output.Add(props[keys[i]], new GH_Path(i)); } } } DA.SetDataTree(0, output); }