/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="dataAccess"> /// The DA object is used to retrieve from inputs and store in outputs. /// </param> protected override void SolveInstance(IGH_DataAccess dataAccess) { dataAccess.SetData(1, false); bool run = false; if (!dataAccess.GetData(3, ref run)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } if (!run) { return; } Analytical.AnalyticalModel analyticalModel = null; if (!dataAccess.GetData(0, ref analyticalModel) || analyticalModel == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } string path = null; if (!dataAccess.GetData(1, ref path) || string.IsNullOrWhiteSpace(path)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } double tolerance = 0.00001; if (!dataAccess.GetData(2, ref tolerance) || double.IsNaN(tolerance)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } gbXML gbXML = analyticalModel.TogbXML(Core.Tolerance.MacroDistance, tolerance); if (gbXML == null) { return; } bool result = Core.gbXML.Create.gbXML(gbXML, path); dataAccess.SetData(0, Core.gbXML.Convert.ToString(gbXML)); dataAccess.SetData(1, result); }
public static string CreateXML(string filename, gbXML gbx) { try { XmlSerializer szer = new XmlSerializer(typeof(gbXML)); TextWriter tw = new StreamWriter(filename); szer.Serialize(tw, gbx); tw.Close(); return("Ok"); } catch (Exception e) { return(e.ToString()); } }
public static Campus GetCampusFromModel(gbXML model) { if (model is null) { return(null); } foreach (var item in model.Items) { if (item is Campus) { return(item as Campus); } } return(null); }
public static DisplayModel Convert(gbXML model) { if (model is null) { return(null); } var campus = ModelQuery.GetCampusFromModel(model); var building = ModelQuery.GetBuildingFromCampus(campus); var spaces = ModelQuery.GetSpacesFromBuilding(building); var displayModel = new DisplayModel(); displayModel.Spaces.AddRange(spaces.Select(ConvertSpace)); displayModel.Floors.AddRange(DisplayModelQuery.CreateFloors(displayModel)); return(displayModel); }
public static bool CreateSerial(string filepath) { //place an in memory object here that represents your class representation of the building List <EPObj.MemorySafe_Spaces> myspace = new List <EPObj.MemorySafe_Spaces>(); myspace = EnergyPlusClass.EPlusSpacestoObjectList(@"C:\Users\Chiensi\Documents\C\Buro Happold\Oregon Sustainability Center\Run 1 + Daylighting Only\Run 1 new.idf"); gb.gbci = new CultureInfo(String.Empty); bool ret = false; //the basics //constructor to define the basics gbXML gbx = new gbXML(); gbx.lengthUnit = lengthUnitEnum.Feet; gbx.temperatureUnit = temperatureUnitEnum.F; string id = "cmps-1"; Campus cmp = CreateCampus(id); cmp.Buildings = new Building[10000]; gbx.Campus = cmp; //where does this location information from? it could be smartly inferred somehow, but otherwise specified by the user/programmer Location zeloc = new Location(); zeloc.Name = "San Francisco, CA"; zeloc.Latitude = "37.795"; zeloc.Longitude = "-122.394"; //end the basics //tie location and campus back to the gbXML file cmp.Location = zeloc; //Define the building(s) on the site //CHarriman Septempber 19 2013 cmp.Buildings[0] = MakeBuilding(2000, "bldg-1", buildingTypeEnum.DiningBarLoungeOrLeisure); //CHarriman September 19 2013 //define the stories for each building //several ways to do this List <List <double> > points = prod.MakeFakeList(5); BuildingStorey bs = MakeStorey(1, points); //CHarriman Jan 15 2014 //define the spaces for each building (these come from a space object elsewhere List <Space> gbSpaces = new List <Space>(); gbSpaces = MakeSpacesFromEPObj(myspace); for (int spacecount = 0; spacecount < gbSpaces.Count(); spacecount++) { cmp.Buildings[0].Spaces[spacecount] = gbSpaces[spacecount]; } //after making all the spaces, I make the surfaces cmp.Surface = new Surface[uniquesurfaces.Count()]; int surfcount = 0; foreach (KeyValuePair <string, Surface> pair in uniquesurfaces) { Surface surf = new Surface(); surf.id = pair.Key; //this is a hard one, how to deal with this? For now, everything is external, and idf can sort of tell me surf.surfaceType = pair.Value.surfaceType; surf.constructionIdRef = pair.Value.constructionIdRef; surf.Name = pair.Value.Name; AdjacentSpaceId[] adjspaces = new AdjacentSpaceId[pair.Value.AdjacentSpaceId.Count()]; int counter = 0; foreach (AdjacentSpaceId adj in pair.Value.AdjacentSpaceId) { adjspaces[counter] = adj; counter++; } surf.AdjacentSpaceId = adjspaces; RectangularGeometry rg = new RectangularGeometry(); rg = pair.Value.RectangularGeometry; surf.RectangularGeometry = rg; surf.PlanarGeometry = pair.Value.PlanarGeometry; cmp.Surface[surfcount] = surf; surfcount++; } cmp.Buildings[0].bldgStories[0] = bs; //write xml to the file XmlSerializer szer = new XmlSerializer(typeof(gbXML)); TextWriter tw = new StreamWriter(filepath); szer.Serialize(tw, gbx); tw.Close(); return(ret); }