Point (1) = {0, 0, 0, 20};
Point (2) = {0, 330, 0, 20};
Point (3) = {330, 330, 0, 20};
Point (4) = {330, 0, 0, 20};
Point (5) = {100, 100, 0, 5};
Point (6) = {100, 130, 0, 5};
Point (7) = {130, 130, 0, 5};
Point (8) = {130, 100, 0, 5};
Point (9) = {200, 200, 0, 5};
Point (10) = {200, 230, 0, 5};
Point (11) = {230, 230, 0, 5};
Point (12) = {230, 200, 0, 5};
Point (13) = {100, 200, 0, 5};
Point (14) = {100, 230, 0, 5};
Point (15) = {130, 230, 0, 5};
Point (16) = {130, 200, 0, 5};
Point (17) = {200, 100, 0, 5};
Point (18) = {200, 130, 0, 5};
Point (19) = {230, 130, 0, 5};
Point (20) = {230, 100, 0, 5};

Line (1) = {2, 3};
Line (2) = {3, 4};
Line (3) = {4, 1};
Line (4) = {1, 2};
Line (5) = {14, 15};
Line (6) = {15, 16};
Line (7) = {16, 13};
Line (8) = {13, 14};
Line (10) = {10, 9};
Line (12) = {10, 11};
Line (13) = {11, 12};
Line (14) = {12, 9};
Line (15) = {6, 7};
Line (16) = {7, 8};
Line (17) = {8, 5};
Line (18) = {5, 6};
Line (19) = {18, 19};
Line (20) = {19, 20};
Line (21) = {20, 17};
Line (22) = {17, 18};
Line (23) = {12, 19};
Line (24) = {9, 18};

// Building 1, 20 m

Line Loop (26) = {13, 14, -10, 12};
Plane Surface (26) = {26};

// Building 2, 10 m

Line Loop (28) = {23, -19, -24, -14};
Plane Surface (28) = {28};

// Building 3, 20 m

Line Loop (30) = {20, 21, 22, 19};
Plane Surface (30) = {30};

// Building 4, 20 m

Line Loop (32) = {6, 7, 8, 5};
Plane Surface (32) = {32};

// Building 5, 20 m

Line Loop (34) = {16, 17, 18, 15};
Plane Surface (34) = {34};

// Ground

Line Loop (37) = {2, 3, 4, 1, -12, 10, 24, -22, -21, -20, -23, -13, -5, -8, -7, -6, -15, -18, -17, -16};
Plane Surface (37) = {37};

// to speed things up

Geometry.AutoCoherence=0; 

// list of buildings and the ground surfaces

s1[] = {26,28,30,32,34,37};
p1[] = {};

For i In {0:#s1[]-1}

// need as many extrusions as you have different building heights...

  e1[] = Extrude {0,0,10} { Surface{s1[i]}; Layers{4}; Recombine; };
  e2[] = Extrude {0,0,10} { Surface{e1[0]}; Layers{4}; Recombine; };
  e3[] = Extrude {0,0,80} { Surface{e2[0]}; Layers{6}; Recombine; };

// no buildings here

  If(s1[i] == 37) 
    p1[] += {e1[1], e2[1]};
  EndIf

// volume above all buildings

  p1[] += e3[1]; 

// add other bits in p1[] depending on height of each building

EndFor

Geometry.AutoCoherence=1;

// remove duplicates

Coherence; 

Physical Volume(1) = p1[];

Physical Surface(674) = {400,502,604};
Physical Surface(675) = {396,498,600};
Physical Surface(676) = {392,494,596};
Physical Surface(677) = {404,506,608};
Physical Surface(678) = {673,169,103,235,367,301};
Physical Surface(679) = {37};

west = 674;
south = 675;
east = 676;
north = 677;
top = 678;
ground = 679;
Show "*";

