-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from CyrilWaechter/FluidType
Add FluidType wrapper including unittest and docstrings
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
40 changes: 40 additions & 0 deletions
40
tests/rpw.extension/rpw.tab/rpw.panel/Plumbing.pushbutton/script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |