Skip to content

Commit

Permalink
Merge pull request #31 from CyrilWaechter/FluidType
Browse files Browse the repository at this point in the history
Add FluidType wrapper including unittest and docstrings
  • Loading branch information
gtalarico committed Nov 13, 2017
2 parents aa41377 + fa749ad commit 6b6d53d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rpw/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
from rpw.db.collector import Collector, ParameterFilter
from rpw.db.transaction import Transaction, TransactionGroup

from rpw.db.plumbing import FluidType

__all__ = [cls for cls in locals().values() if isinstance(cls, type)]
66 changes: 66 additions & 0 deletions rpw/db/plumbing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# coding: utf8

"""
Plumbing Wrapper
"""

from rpw.db import Element
from rpw import revit, DB


class FluidType(Element):
""" Autodesk.Revit.DB.Plumbing.FluidType wrapper
Inherits from rpw.db.Element
>>> from rpw.db import FluidType
Example to return a dictionary of fluids in use with system as key
>>> FluidType.in_use_dict() # return format: {system.name:{'name':fluid.name, 'temperature':temperature}
{'Hydronic Return': {'name': 'Water', 'temperature': 283.15000000000003}, ...}
FluidType wrapper is collectible:
>>> FluidType.collect()
<rpw:Collector % FilteredElementCollector [count:19]>
"""
_revit_object_class = DB.Plumbing.FluidType
_collector_params = {'of_class': _revit_object_class, 'is_type': True}

def __repr__(self, data=None):
""" Adds data to Base __repr__ to add Parameter List Name """
if not data:
data = {}
data['name'] = self.name
return super(FluidType, self).__repr__(data=data)

@staticmethod
def in_use_dict(doc=revit.doc):
""" Return a dictionary of fluids in use with system as key
>>> FluidType.in_use_dict() # return format: {system.name:{'name':fluid.name, 'temperature':temperature}
{'Hydronic Return': {'name': 'Water', 'temperature': 283.15000000000003}, ...}
"""
result = {}
for system in DB.FilteredElementCollector(doc).OfClass(DB.Plumbing.PipingSystemType):
rpw_system = Element(system)
rpw_fluid_type = Element.from_id(system.FluidType)
result[rpw_system.name] = {'name': rpw_fluid_type.name, 'temperature': rpw_system.FluidTemperature}
return result

@property
def fluid_temperatures(self):
""" Return an iterable of all FluidTemperature in current FluidType as native GetFluidTemperatureSetIterator
method is not very intuitive
>>> fluid_type.fluid_temperatures
<Autodesk.Revit.DB.Plumbing.FluidTemperatureSetIterator object at 0x00000000000002E9...
>>> for fluid_temperature in fluid_type.fluid_temperatures:
>>> fluid_temperature
<Autodesk.Revit.DB.Plumbing.FluidTemperature object at 0x00000000000002EC...
<Autodesk.Revit.DB.Plumbing.FluidTemperature object at 0x00000000000002ED...
...
"""
return self.GetFluidTemperatureSetIterator()

@property
def temperatures(self):
""" Return (list) a sorted list of temperatures (double) in current FluidType
[272.15000000000003, 277.59444444444449, 283.15000000000003, 288.70555555555563, ...]
"""
return sorted([temp.Temperature for temp in self.fluid_temperatures])
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# coding: utf8

import sys
import unittest
import os

parent = os.path.dirname

script_dir = parent(__file__)
panel_dir = parent(script_dir)
sys.path.append(script_dir)

import rpw
from rpw import DB, revit
from rpw.utils.logger import logger
from rpw.db import Element
from rpw.db import FluidType


class TestFluidTypeWrapper(unittest.TestCase):

@classmethod
def setUpClass(cls):
logger.title('TESTING FluidType Wrapper...')
cls.fluidtype = DB.FilteredElementCollector(revit.doc).OfClass(DB.Plumbing.FluidType).FirstElement()

def test_fluidtype_wrapper(self):
wrapped_fluidtype = Element(self.fluidtype)
self.assertIsInstance(wrapped_fluidtype, FluidType)
wrapped_fluidtype = FluidType(self.fluidtype)
self.assertIsInstance(wrapped_fluidtype, FluidType)

def run():
logger.verbose(False)
suite = unittest.TestLoader().discover(os.path.dirname(__file__))
unittest.main(verbosity=3, buffer=True)


if __name__ == '__main__':
run()

0 comments on commit 6b6d53d

Please sign in to comment.