Skip to content

Commit

Permalink
Implemented #454
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Dec 21, 2018
1 parent a465964 commit 46e39fe
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pylint: disable=E0401,C0103
from pyrevit import revit, DB
from pyrevit import script


output = script.get_output()


__context__ = 'selection'
Expand Down Expand Up @@ -43,7 +47,13 @@
if area.AreaScheme.Name == el.AreaScheme.Name\
and selareaname == areaname:
area_param = area.Parameter[DB.BuiltInParameter.ROOM_AREA]
total += area_param.AsDouble()
area_val = area_param.AsDouble()
print('+ Area \"{}\" = {}'.format(
output.linkify(area.Id),
areaname,
revit.units.format_area(area_val)
))
total += area_val
count += 1
print("TOTAL OF {} AREAS WERE FOUND.".format(count))
processed_items[DB.Area].append(selareaname)
Expand All @@ -56,7 +66,13 @@
room.Parameter[DB.BuiltInParameter.ROOM_NAME].AsString()
if selroomname == roomname:
area_param = room.Parameter[DB.BuiltInParameter.ROOM_AREA]
total += area_param.AsDouble()
area_val = area_param.AsDouble()
print('{} Room \"{}\" = {}'.format(
output.linkify(room.Id),
roomname,
revit.units.format_area(area_val)
))
total += area_val
count += 1
print("TOTAL OF {} ROOMS WERE FOUND.".format(count))
processed_items[DB.Architecture.Room].append(selroomname)
Expand All @@ -69,13 +85,21 @@
space.Parameter[DB.BuiltInParameter.ROOM_NAME].AsString()
if selspacename == spacename:
area_param = space.Parameter[DB.BuiltInParameter.ROOM_AREA]
total += area_param.AsDouble()
area_val = area_param.AsDouble()
print('{} Space \"{}\" = {}'.format(
output.linkify(space.Id),
spacename,
revit.units.format_area(area_val)
))
total += area_val
count += 1
print("TOTAL OF {} SPACES WERE FOUND.".format(count))
processed_items[DB.Mechanical.Space].append(selspacename)

if count != 0:
average = total / count
print('AVERAGE AREA OF THE SELECTED TYPE IS:'
'\n{0} SQFT'
'\n{1} ACRE'.format(average, average / 43560))
print('\nAVERAGE AREA OF THE SELECTED TYPE IS:'
'\n{0}'
'\n ======================================='
'\n{1} ACRE'.format(revit.units.format_area(average),
average / 43560))
1 change: 1 addition & 0 deletions pyrevitlib/pyrevit/revit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pyrevit.revit import files
from pyrevit.revit import serverutils
from pyrevit.revit import geom
from pyrevit.revit import units


#pylint: disable=W0703,C0302,C0103
Expand Down
22 changes: 22 additions & 0 deletions pyrevitlib/pyrevit/revit/units.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Unit conversion utilities for Revit."""

from pyrevit import HOST_APP
from pyrevit import DB


def format_area(area_value, doc=None):
"""Return formatted area value in document units.
Args:
area_value (float): area value
doc (DB.Document, optional): Revit document, defaults to current
Returns:
str: formatted value
"""
doc = doc or HOST_APP.doc
return DB.UnitFormatUtils.Format(units=doc.GetUnits(),
unitType=DB.UnitType.UT_Area,
value=area_value,
maxAccuracy=False,
forEditing=False)

0 comments on commit 46e39fe

Please sign in to comment.