Set up a workbook (Shading objects)
Shading regions
To enumerate all the current shading regions in the workbook use Workbook.ShadingRegions
// Enumerate through the existing shading regions in the workbook, printing out information
// for each
Toolbox.Log(string.Format("Number of shading regions = {0}", Workbook.ShadingRegions.Count()));
foreach (ShadingRegion shadingRegion in Workbook.ShadingRegions)
{
Toolbox.Log(string.Format("Shading region: {0}, height={1}, ShadingBoundaryType={2}",
shadingRegion.Name,
shadingRegion.Height,
shadingRegion.ShadingBoundaryType));
Toolbox.Log(string.Format(" Points ({0} points): {1}",
shadingRegion.Points.Count(),
string.Join(", ",
shadingRegion.Points
.Select(p => string.Format("({0},{1})", p.X, p.Y)))));
}
Adding a new shading region
To add a new shading region use Workbook.AddShadingRegion()
// Get a reference to shading region with name "Shading region 3"
ShadingRegion shadingRegion3 = Workbook.ShadingRegions
.First(s => s.Name == "Shading region 3");
// Add a new shading region 20 metres to the west of the existing one, which is a copy of the
// points of the existing one, with a height of 6.6m and a flat top.
ShadingRegion shade3 = Workbook.AddShadingRegion(
"Shade 3", // new name
shadingRegion3.Points.Select(p => new Location(p.X - 20, p.Y)),
6.6, // height of 6.6m
ShadingBoundaryType.FlatTop);
Removing shading regions
To remove all the shading regions in the workbook use Workbook.RemoveAllShadingRegions()
// Remove all shading regions in the workbook
Workbook.RemoveAllShadingRegions();
To remove a specific shading region use Workbook.RemoveShadingRegion()
// Remove a specific shading region
ShadingRegion shadingRegionToRemove = Workbook.ShadingRegions
.First(s => s.Name == "Shading region 1");
Workbook.RemoveShadingRegion(shadingRegionToRemove);
3D model shading objects
It is not currently possible to add/import 3D model shading objects from 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);
Adding parapets to a building region
To add a parapet to a building region use the method BuildingRegion.AddParapets()
// Adding parapets to all building regions.
// Parapet dimensions 1.5 metres height, 0.2 metres width and a continuous parapet
double parapetHeight = 1.5;
double parapetWidth = 0.2;
bool createSeparateParapetPerEdge = false;
foreach (BuildingRegion buildingRegion in Workbook.BuildingRegions)
{
buildingRegion.AddParapets(parapetHeight, parapetWidth, createSeparateParapetPerEdge);
}
// Adding parapets to a specific building of interest named 'Building region 1':
// Identify the building of interest
BuildingRegion buildingOfInterest = Workbook.BuildingRegions
.First(s => s.Name == "Building region 1");
// Add the parapet to the building
buildingOfInterest.AddParapets(parapetHeight: 1.2,
parapetWidth: 0.1,
createSeparateParapetPerEdge: false);
Getting the shading objects
You may have a need to get the 3D shading objects (from shading regions, building regions, and the 3D models) in the form of triangles and quads to use for your own purposes, such as to use in other software in your work flow.
There are a couple of functions you can use:
- IReadOnlyCollection<ShadingObjectPoints> SiteLayout.GetShadingObjectsAsPointObjects()
- Each ShadingObjectPoints object contains:
- A list of triangles (TrianglePoints objects)
- A list of quads (QuadPoints objects)
- Each triangle and quad contains the points that they are constructed of.
- The X,Y values of the points are in the workbook projection (same as in the 2D map), and the Z value is
the altitude above sea level (in metres).
- Each ShadingObjectPoints object contains:
- IReadOnlyCollection<ShadingObjectIndexed> SiteLayout.GetShadingObjectsAsIndexedObjects()
- Each ShadingObjectIndexed object contains:
- A list of vertices (the X,Y values of the points are in the workbook projection (same as in the 2D map), and the Z value is the altitude above sea level (in metres))
- A list of triangles (TriangleIndices objects)
- A list of quads (QuadIndices objects)
- The triangles and quads contain indices into the list of vertices, rather than the point data itself; This is a slightly more efficient data structure.
- Each ShadingObjectIndexed object contains:
The following code snippet prints out the shading objects in your current workbook. So use this as a template.
/// <Summary>
/// The main entry point of the script.
/// </Summary>
public void Execute()
{
PrintShadingObjectAsPoints();
PrintShadingObjectAsIndexedObjects();
}
private void PrintShadingObjectAsPoints()
{
IReadOnlyCollection<ShadingObjectPoints> shadingObjects =
Workbook.Domain.VisibleSiteLayout.GetShadingObjectsAsPointObjects();
Toolbox.Log(string.Format("Number of shading objects = {0}", shadingObjects.Count));
foreach (ShadingObjectPoints shadingObject in shadingObjects)
{
Toolbox.Log(string.Format("Name = \"{0}\"", shadingObject.Name));
Toolbox.Log(string.Format(" Num quads = {0}", shadingObject.Quads.Count));
Toolbox.Log(string.Format(" Num triangles = {0}", shadingObject.Triangles.Count));
// Print out the quads
if (shadingObject.Quads.Any())
{
foreach (QuadPoints quad in shadingObject.Quads)
{
Toolbox.Log(string.Format(" Quad: P1={0},{1},{2} P2={3},{4},{5} P3={6},{7},{8} P4={9},{10},{11}",
quad.P1.X, quad.P1.Y, quad.P1.Z,
quad.P2.X, quad.P2.Y, quad.P2.Z,
quad.P3.X, quad.P3.Y, quad.P3.Z,
quad.P4.X, quad.P4.Y, quad.P4.Z));
}
}
// Print out the triangles
if (shadingObject.Triangles.Any())
{
foreach (TrianglePoints triangle in shadingObject.Triangles)
{
Toolbox.Log(string.Format(" Triangle: P1={0},{1},{2} P2={3},{4},{5} P3={6},{7},{8}",
triangle.P1.X, triangle.P1.Y, triangle.P1.Z,
triangle.P2.X, triangle.P2.Y, triangle.P2.Z,
triangle.P3.X, triangle.P3.Y, triangle.P3.Z));
}
}
}
}
private void PrintShadingObjectAsIndexedObjects()
{
IReadOnlyCollection<ShadingObjectIndexed> shadingObjects =
Workbook.Domain.VisibleSiteLayout.GetShadingObjectsAsIndexedObjects();
Toolbox.Log(string.Format("Number of shading objects = {0}", shadingObjects.Count));
foreach (ShadingObjectIndexed shadingObject in shadingObjects)
{
Toolbox.Log(string.Format("Name = \"{0}\"", shadingObject.Name));
Toolbox.Log(string.Format(" Num vertices = {0}", shadingObject.Vertices.Count));
Toolbox.Log(string.Format(" Num quads = {0}", shadingObject.Quads.Count));
Toolbox.Log(string.Format(" Num triangles = {0}", shadingObject.Triangles.Count));
// Print out the vertices
if (shadingObject.Vertices.Any())
{
foreach (Point3D vertex in shadingObject.Vertices)
{
Toolbox.Log(string.Format(" Vertex: {0}, {1}, {2}",
vertex.X, vertex.Y, vertex.Z));
}
}
// Print out the quads
if (shadingObject.Quads.Any())
{
foreach (QuadIndices quad in shadingObject.Quads)
{
Toolbox.Log(string.Format(" Quad: {0}, {1}, {2}, {3}",
quad.P1, quad.P2, quad.P3, quad.P4));
}
}
// Print out the triangles
if (shadingObject.Triangles.Any())
{
foreach (TriangleIndices triangle in shadingObject.Triangles)
{
Toolbox.Log(string.Format(" Triangle: {0}, {1}, {2}",
triangle.P1, triangle.P2, triangle.P3));
}
}
}
}