Set up a workbook (Site)
Site location
Set the site location
Use the following function to set the site location:
Toolbox.SetSiteLocationAndAutomaticallySetProjection(double latitude, double longitude)
This also automatically sets the workbook projection (to the correct UTM zone for the location) and the time zone. Make sure you get the latitude and the longitude the right way around!
E.g.,
// Set site location of latitude of 24.928430 and longitude of 66.918926
Toolbox.SetSiteLocationAndAutomaticallySetProjection(24.928430, 66.918926);
Map backgrounds/terrain
Adding, downloading and removing map backgrounds and terrain is not currently supported in scripting.
Building regions
To enumerate all the current building regions in the workbook use Workbook.BuildingRegions
// Enumerate through the existing building regions in the workbook, printing out information
// for each
Toolbox.Log(string.Format("Number of building regions = {0}", Workbook.BuildingRegions.Count()));
foreach (BuildingRegion buildingRegion in Workbook.BuildingRegions)
{
Toolbox.Log(string.Format("Building region: {0}, height={1}, BuildingBoundaryType={2}",
buildingRegion.Name,
buildingRegion.Height,
buildingRegion.BuildingBoundaryType));
Toolbox.Log(string.Format(" Points ({0} points): {1}",
buildingRegion.Points.Count(),
string.Join(", ",
buildingRegion.Points
.Select(p => string.Format("({0},{1})", p.X, p.Y)))));
}
Adding a new building region
To add a new building region use Workbook.AddBuildingRegion()
// Get a reference to building region with name "Building region 1"
BuildingRegion buildingRegion1 = Workbook.BuildingRegions
.First(s => s.Name == "Building region 1");
// Add a new building region 70 metres to the west of the existing one, which is a copy of the
// points of the existing one, with a height of 20m and a flat top.
BuildingRegion building20m = Workbook.AddBuildingRegion(
"Building (20m)", // new name
buildingRegion1.Points.Select(p => new Location(p.X - 70, p.Y)),
20.0, // height of 20m
BuildingBoundaryType.FlatTop);
Removing building regions
To remove all the building regions in the workbook use Workbook.RemoveAllBuildingRegions()
// Remove all building regions in the workbook
Workbook.RemoveAllBuildingRegions();
To remove a specific building region use Workbook.RemoveBuildingRegion()
// Remove a specific building region
BuildingRegion buildingRegionToRemove = Workbook.BuildingRegions
.First(s => s.Name == "Building region 1");
Workbook.RemoveBuildingRegion(buildingRegionToRemove);
Horizon line
Load horizon data from a file
// Load PVsyst-format horizon data from a file
const string pvSystHorizonFilePath = @"C:\Data\Components\TestHorizon.hor";
const bool isNorthernHemisphere = true;
HorizonData horizonData = HorizonData.ReadPVsystHorizonFile(pvSystHorizonFilePath, isNorthernHemisphere);
// Add the loaded horizon data to the workbook
Workbook.Domain.Geography.HorizonData.Add(horizonData);