diff --git a/pyRevitMEP.tab/Fluid.panel/FluidCreate.pushbutton/CoolProp_x64.dll b/pyRevitMEP.tab/Fluid.panel/FluidCreate.pushbutton/CoolProp_x64.dll new file mode 100644 index 0000000..dd9ad4e Binary files /dev/null and b/pyRevitMEP.tab/Fluid.panel/FluidCreate.pushbutton/CoolProp_x64.dll differ diff --git a/pyRevitMEP.tab/Fluid.panel/FluidCreate.pushbutton/script.py b/pyRevitMEP.tab/Fluid.panel/FluidCreate.pushbutton/script.py index e69de29..8e393f7 100644 --- a/pyRevitMEP.tab/Fluid.panel/FluidCreate.pushbutton/script.py +++ b/pyRevitMEP.tab/Fluid.panel/FluidCreate.pushbutton/script.py @@ -0,0 +1,94 @@ +# coding: utf8 + +# noinspection PyUnresolvedReferences +from Autodesk.Revit import Exceptions +# noinspection PyUnresolvedReferences +from Autodesk.Revit.DB import Transaction, UnitUtils, DisplayUnitType +# noinspection PyUnresolvedReferences +from Autodesk.Revit.DB.Plumbing import FluidType, FluidTemperature +# noinspection PyUnresolvedReferences +from Autodesk.Revit.UI import TaskDialog, TaskDialogCommonButtons, TaskDialogResult +import ctypes +import os +import rpw + +__doc__ = "Create a Fluid with all temperatures within desired range" +__title__ = "Create a fluid" +__author__ = "Cyril Waechter" + +ComboBox = rpw.ui.forms.flexform.ComboBox +Label = rpw.ui.forms.flexform.Label +TextBox = rpw.ui.forms.flexform.TextBox +Button = rpw.ui.forms.flexform.Button + +#Load CoolProp shared library and configure PropsSI c_types units +CP = ctypes.cdll.LoadLibrary(os.path.join(__commandpath__, "CoolProp_x64.dll")) +PropsSI = CP.PropsSI +PropsSI.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_double, ctypes.c_char_p, ctypes.c_double, ctypes.c_char_p) +PropsSI.restype = ctypes.c_double + +uidoc = __revit__.ActiveUIDocument +doc = __revit__.ActiveUIDocument.Document + +fluid_list = ['1-Butene', 'Acetone', 'Air', 'Ammonia', 'Argon', 'Benzene', 'CarbonDioxide', 'CarbonMonoxide', 'CarbonylSulfide', 'cis-2-Butene', 'CycloHexane', 'Cyclopentane', 'CycloPropane', 'D4', 'D5', 'D6', 'Deuterium', 'Dichloroethane', 'DiethylEther', 'DimethylCarbonate', 'DimethylEther', 'Ethane', 'Ethanol', 'EthylBenzene', 'Ethylene', 'EthyleneOxide', 'Fluorine', 'HeavyWater', 'Helium', 'HFE143m', 'Hydrogen', 'HydrogenChloride', 'HydrogenSulfide', 'IsoButane', 'IsoButene', 'Isohexane', 'Isopentane', 'Krypton', 'm-Xylene', 'MD2M', 'MD3M', 'MD4M', 'MDM', 'Methane', 'Methanol', 'MethylLinoleate', 'MethylLinolenate', 'MethylOleate', 'MethylPalmitate', 'MethylStearate', 'MM', 'n-Butane', 'n-Decane', 'n-Dodecane', 'n-Heptane', 'n-Hexane', 'n-Nonane', 'n-Octane', 'n-Pentane', 'n-Propane', 'n-Undecane', 'Neon', 'Neopentane', 'Nitrogen', 'NitrousOxide', 'Novec649', 'o-Xylene', 'OrthoDeuterium', 'OrthoHydrogen', 'Oxygen', 'p-Xylene', 'ParaDeuterium', 'ParaHydrogen', 'Propylene', 'Propyne', 'R11', 'R113', 'R114', 'R115', 'R116', 'R12', 'R123', 'R1233zd(E)', 'R1234yf', 'R1234ze(E)', 'R1234ze(Z)', 'R124', 'R125', 'R13', 'R134a', 'R13I1', 'R14', 'R141b', 'R142b', 'R143a', 'R152A', 'R161', 'R21', 'R218', 'R22', 'R227EA', 'R23', 'R236EA', 'R236FA', 'R245ca', 'R245fa', 'R32', 'R365MFC', 'R40', 'R404A', 'R407C', 'R41', 'R410A', 'R507A', 'RC318', 'SES36', 'SulfurDioxide', 'SulfurHexafluoride', 'Toluene', 'trans-2-Butene', 'Water', 'Xenon'] + +form_items = [Label("Pick a fluid"), + ComboBox("fluid", fluid_list), + Label("Set fluid name"), + TextBox("name"), + Label("Set fluid starting temperature (°C)"), + TextBox("t_start"), + Label("Set fluid last temperature (°C)"), + TextBox("t_end"), + Label("Set step between each temperature)"), + TextBox("t_step"), + Button("Select")] + +form = rpw.ui.forms.FlexForm("FluidSelection", form_items) +form.show() + + +#Set desired fluid, initial temperature(freezing temperature ?), desired pressure for properties call +fluid = form.values["fluid"] +fluid_name = form.values["name"] +t_init = 273.15 +t_start = int(form.values["t_start"]) +t_end = int(form.values["t_end"]) +pressure = 101325 + +#Check if fluid_type exist and create it if not +fluid_type = FluidType.GetFluidType(doc, fluid_name) +if fluid_type is None: + t = Transaction(doc, "Create fluid type") + t.Start() + FluidType.Create(doc, fluid_name) + t.Commit() + fluid_type = FluidType.GetFluidType(doc, fluid_name) + +#Add new temperature with associated heat capacity and viscosity +t = Transaction(doc, "Add temperature") +t.Start() +for i in xrange(t_start, t_end+1): + #Call CoolProp to get fluid properties and convert it to internal units if necessary + temperature = t_init+i + viscosity = UnitUtils.ConvertToInternalUnits(PropsSI('V', 'T', temperature, 'P', pressure, fluid), + DisplayUnitType.DUT_PASCAL_SECONDS) + density = UnitUtils.ConvertToInternalUnits(PropsSI('D','T',temperature,'P',pressure,fluid), + DisplayUnitType.DUT_KILOGRAMS_PER_CUBIC_METER) + #Catching exceptions and trying to overwrite temperature if asked by user in the TaskDialog + try: + fluid_type.AddTemperature(FluidTemperature(temperature,viscosity,density)) + except Exceptions.ArgumentException: + result = TaskDialog.Show("Error", "Temperature already exist, do you want to overwrite it ?", TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No | TaskDialogCommonButtons.Cancel, TaskDialogResult.Yes) + if result == TaskDialogResult.Yes: + try: + fluid_type.RemoveTemperature(temperature) + fluid_type.AddTemperature(FluidTemperature(temperature,viscosity,density)) + except Exceptions.ArgumentException: + TaskDialog.Show("Overwrite error", "Temperature is currently in use and cannot be overwritten") + elif result == TaskDialogResult.No: + pass + else: + break +t.Commit() + diff --git a/pyRevitMEP.tab/Tools.panel/Copy.pulldown/CopyPipeType.pushbutton/script.py b/pyRevitMEP.tab/Tools.panel/Copy.pulldown/CopyPipeType.pushbutton/script.py index fc90388..ef89c6c 100644 --- a/pyRevitMEP.tab/Tools.panel/Copy.pulldown/CopyPipeType.pushbutton/script.py +++ b/pyRevitMEP.tab/Tools.panel/Copy.pulldown/CopyPipeType.pushbutton/script.py @@ -32,9 +32,6 @@ __title__ = "Copy pipe type" __author__ = "Cyril Waechter" -ComboBox = rpw.ui.forms.flexform.ComboBox -Label = rpw.ui.forms.flexform.Label -Button = rpw.ui.forms.flexform.Button opened_docs = {} for d in __revit__.Application.Documents: @@ -72,7 +69,7 @@ def copy(source_doc, elem): t.Commit() -class ReferenceLevelSelection(WPFWindow): +class PipeTypeSelectionForm(WPFWindow): ''' GUI used to select pipe type to copy ''' @@ -95,5 +92,5 @@ def button_copy_click(self, sender, e): copy(self.source_doc, elem) -ReferenceLevelSelection('PipeTypeSelection.xaml').ShowDialog() +PipeTypeSelectionForm('PipeTypeSelection.xaml').ShowDialog() diff --git a/pyRevitMEP.tab/Tools.panel/Copy.pulldown/CopyViewType.pushbutton/script.py b/pyRevitMEP.tab/Tools.panel/Copy.pulldown/CopyViewType.pushbutton/script.py index d75b9ac..42e69ae 100644 --- a/pyRevitMEP.tab/Tools.panel/Copy.pulldown/CopyViewType.pushbutton/script.py +++ b/pyRevitMEP.tab/Tools.panel/Copy.pulldown/CopyViewType.pushbutton/script.py @@ -24,8 +24,8 @@ import rpw -__doc__ = "Copy view types from a selected opened project to another" -__title__ = "Copy view type" +__doc__ = "Copy all view types from a selected opened project to another" +__title__ = "Copy view types" __author__ = "Cyril Waechter" ComboBox = rpw.ui.forms.flexform.ComboBox