pyRevit

Code
Library
Sum Selected Rooms
# -*- coding: utf-8 -*-
__title__ = "03.04 - Sum Rooms"
__doc__ = """Date = 02.01.2023
_____________________________________________________________________
Description:
Tool to Sum selected Rooms.
If no rooms selected, you will be asked to select them.
_____________________________________________________________________
Author: Erik Frits"""
# ╦╔╦╗╔═╗╔═╗╦═╗╔╦╗╔═╗
# ║║║║╠═╝║ ║╠╦╝ ║ ╚═╗
# ╩╩ ╩╩ ╚═╝╩╚═ ╩ ╚═╝ IMPORTS
#==================================================
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import Room
from Autodesk.Revit.UI.Selection import ObjectType, PickBoxStyle, Selection
# CUstom
from Snippets._selection import ISelectionFilter_Classes
from Snippets._convert import convert_internal_units
# .NET Imports
import clr
clr.AddReference("System")
from System.Collections.Generic import List
# ╦ ╦╔═╗╦═╗╦╔═╗╔╗ ╦ ╔═╗╔═╗
# ╚╗╔╝╠═╣╠╦╝║╠═╣╠╩╗║ ║╣ ╚═╗
# ╚╝ ╩ ╩╩╚═╩╩ ╩╚═╝╩═╝╚═╝╚═╝ VARIABLES
#==================================================
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
selection = uidoc.Selection # type: Selection
# ╔╦╗╔═╗╦╔╗╔
# ║║║╠═╣║║║║
# ╩ ╩╩ ╩╩╝╚╝
#==================================================
# GET ROOMS
selected_elements = [doc.GetElement(e_id) for e_id in selection.GetElementIds()]
selected_rooms = [el for el in selected_elements if type(el) == Room]
if not selected_rooms:
filter_types = ISelectionFilter_Classes([Room])
ref_picked_rooms = selection.PickObjects(ObjectType.Element, filter_types)
selected_rooms = [doc.GetElement(ref) for ref in ref_picked_rooms]
if not selected_rooms:
print('There were no Rooms selected. Please Try Again.')
import sys
sys.exit()
# GET VALUES
total = 0
total_b = 0
for room in selected_rooms:
room_name = room.get_Parameter(BuiltInParameter.ROOM_NAME).AsString()
area_m2 = convert_internal_units(room.Area, get_internal=False, units='m2')
area_m2_rounded = round(area_m2, 2)
total += area_m2_rounded
print("{}: {}m²".format(room_name, area_m2_rounded))
# PRINT RESULTS
print('-'*20)
print("Total: {}m²".format( total))
print('Selected {} Rooms.'.format(len(selected_rooms)))

⌨️ Happy Coding!
Erik Frits