When sketching out building volumes, getting floor areas quickly out of Rhino requires quite a few steps. Either you have to individually select faces, extract face curves or run a complicated grasshopper script. All steps that get in the way of the flow when modelling design options.
Could someone help with pulling a python script together that gives the total floor area of the extrusions shown below? Note that one volume is 2 stories (one above another volume). Ideally this is something that can be run once you’ve selected the relevant breps, showing you quickly how much m2 (for example) you currently have. It would be great if it could also deal with blocks too.
Below I have got a rudimentary script working in python.
import rhinoscriptsyntax as rs
def calculate_footprint_area():
# Prompt the user to select multiple polysurfaces
polysurface_ids = rs.GetObjects("Select polysurfaces", rs.filter.polysurface)
if not polysurface_ids:
print("No polysurfaces selected.")
return
total_area = 0.0 # Initialize total area
# Loop through each selected polysurface
for polysurface_id in polysurface_ids:
print("Processing polysurface ID:", polysurface_id)
# Get the individual faces of the polysurface
face_ids = rs.ExplodePolysurfaces(polysurface_id, delete_input=False)
if not face_ids:
print("Failed to explode polysurface into faces.")
continue
# Find the lowest face based on its centroid's Z-coordinate
lowest_face = None
lowest_z = float("inf")
for face_id in face_ids:
centroid = rs.SurfaceAreaCentroid(face_id)
if centroid:
z_coordinate = centroid[0][2] # Centroid is a tuple: ([x, y, z], area)
if z_coordinate < lowest_z:
lowest_face = face_id
lowest_z = z_coordinate
if not lowest_face:
print("Failed to determine the lowest face for polysurface ID:", polysurface_id)
continue
# Calculate the area of the lowest face
area_info = rs.SurfaceArea(lowest_face)
if area_info:
area = area_info[0]
total_area += area # Add to total area
# Optionally, delete the temporary exploded faces
rs.DeleteObjects(face_ids)
# Output the total area of the lowest faces
print("Total area footprint: {:.2f}".format(total_area))
# Run the function
calculate_footprint_area()
It’s still missing some functionality - any help on this would be greatly appreciated:
Give user the ability to choose which unit and number of decimal places to output the area in (with correct unit suffix… for example “Total area footprint: 90.2m²” - like the ‘area’ command does.
Ability to select blocks and include polysurfaces within the blocks to this total calculation.
You could make this script a rhinocommand with the ScriptEditor, use getstring in your code for the command line options/selections of the user such as “unit selection” and compile it with the script editor as well.
Then when you have the command installed you just run it “MyAreaTool” and you will be prompted to make the unit selections and select the objects for the area calc from your script.
haven’t worked in python, but i have a similar script from an old project in grasshopper that made use of geometry pipelines that gives simultaneous results.
the script works with blocks – by entering into a block, the geometry pipeline only checks geometry inside the block. works nicely with keeping design options in blocks.
@michaelvollrath - thanks for the response. Working on Rhino 7 for Mac (and with a lot of help from Claude.ai) is getting a bit limiting (python 2.7 is causing confusion). I’ll have another go next week on Windows.
@BTH - Thanks for sharing your script. I have also built similar ones, but I’m trying to make a super simple script that doesn’t get in the way of modelling. I find having to load up grasshopper and fiddle with settings is often a distraction.