Skip to content

Commit

Permalink
New script : FluidCreate
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilWaechter committed Aug 7, 2017
1 parent 5ca1302 commit f911d77
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 7 deletions.
Binary file not shown.
94 changes: 94 additions & 0 deletions pyRevitMEP.tab/Fluid.panel/FluidCreate.pushbutton/script.py
Original file line number Diff line number Diff line change
@@ -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()

Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
'''
Expand All @@ -95,5 +92,5 @@ def button_copy_click(self, sender, e):
copy(self.source_doc, elem)


ReferenceLevelSelection('PipeTypeSelection.xaml').ShowDialog()
PipeTypeSelectionForm('PipeTypeSelection.xaml').ShowDialog()

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f911d77

Please sign in to comment.