{"id":155,"date":"2015-11-08T22:04:05","date_gmt":"2015-11-08T20:53:12","guid":{"rendered":"http:\/\/pythoncvc.net\/?p=155"},"modified":"2015-11-08T22:46:00","modified_gmt":"2015-11-08T21:46:00","slug":"revit-adding-fluids-using-coolprop","status":"publish","type":"post","link":"https:\/\/pythoncvc.net\/?p=155","title":{"rendered":"[Revit] Adding fluids using CoolProp"},"content":{"rendered":"<p><iframe loading=\"lazy\" title=\"[Revit] Add fluids to Revit using CoolProp\" width=\"620\" height=\"349\" src=\"https:\/\/www.youtube.com\/embed\/rKIBSspQIg4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>Sometimes you need to add new temperature in your project for at least 3 reasons :<\/p>\n<ul>\n<li>When you use SI units Revit default fluids are bugged. I have seen them bugged for more than 5 years&#8230; Templates were made in Fahrenheit and some temperatures just don&rsquo;t work when converted into \u00b0C or K.<\/li>\n<li>Revit default fluids don&rsquo;t have enough temperatures. About 5K between each and they usually just don&rsquo;t fit the temperature you need in your project.<\/li>\n<li>Water, ethylene and propylene glycol are the only default fluid available.<\/li>\n<\/ul>\n<p>Here is a script example to add water to Revit. This way you can add any fluid available in CoolProp to Revit :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">from Autodesk.Revit.DB import *\r\nfrom Autodesk.Revit.DB.Architecture import *\r\nfrom Autodesk.Revit.DB.Analysis import *\r\nfrom Autodesk.Revit.DB.Plumbing import *\r\nfrom Autodesk.Revit.Exceptions import *\r\nfrom Autodesk.Revit.UI import TaskDialogCommonButtons\r\nfrom Autodesk.Revit.UI import TaskDialogResult\r\nimport ctypes\r\n\r\n#Load CoolProp shared library and configure PropsSI c_types units\r\nCP = ctypes.cdll.LoadLibrary(r\"E:\\Cyril\\Dropbox\\CVC\\BIM_Revit\\ScriptsPython\\dll\\CoolProp.dll\")\r\nPropsSI = CP.PropsSI\r\nPropsSI.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_double, ctypes.c_char_p, ctypes.c_double, ctypes.c_char_p)\r\nPropsSI.restype = ctypes.c_double\r\n\r\nuidoc = __revit__.ActiveUIDocument\r\ndoc = __revit__.ActiveUIDocument.Document\r\n\r\n#Set desired fluid, initial temperature(freezing temperature ?), desired pressure for properties call\r\nfluid = 'Water'\r\nt_init = 273.15\r\npressure = 101325\r\n\r\n#Check if fluid_type exist and create it if not\r\nfluid_type = FluidType.GetFluidType(doc, fluid)\r\nif fluid_type == None:\r\n\tt = Transaction(doc, \"Create fluid type\")\r\n\tt.Start()\r\n\tFluidType.Create(doc, fluid)\r\n\tt.Commit()\r\n\tfluid_type = FluidType.GetFluidType(doc, fluid)\r\n\r\n#Add new temperature with associated heat capacity and viscosity\r\nt = Transaction(doc, \"Add temperature\")\r\nt.Start()\r\nfor i in range(1,100):\r\n\t#Call CoolProp to get fluid properties and convert it to internal units if necessary \r\n\ttemperature = 273.15+i\r\n\tviscosity = UnitUtils.ConvertToInternalUnits(PropsSI('V','T',t_init+i,'P',pressure,fluid),DisplayUnitType.DUT_PASCAL_SECONDS)\r\n\tdensity = UnitUtils.ConvertToInternalUnits(PropsSI('D','T',t_init+i,'P',pressure,fluid),DisplayUnitType.DUT_KILOGRAMS_PER_CUBIC_METER)\r\n\t#Catching exceptions and trying to overwrite temperature if asked by user in the TaskDialog\r\n\ttry:\r\n\t\tfluid_type.AddTemperature(FluidTemperature(temperature,viscosity,density))\r\n\texcept ArgumentException:\r\n\t\tresult = TaskDialog.Show(\"Error\", \"Temperature already exist, do you want to overwrite it ?\",TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No | TaskDialogCommonButtons.Cancel, TaskDialogResult.Yes)\r\n\t\tif result == TaskDialogResult.Yes:\r\n\t\t\ttry:\r\n\t\t\t\tfluid_type.RemoveTemperature(temperature)\r\n\t\t\t\tfluid_type.AddTemperature(FluidTemperature(temperature,viscosity,density))\r\n\t\t\texcept ArgumentException:\r\n\t\t\t\tTaskDialog.Show(\"Overwrite error\", \"Temperature is currently in use and cannot be overwritten\")\r\n\t\telif result == TaskDialogResult.No:\r\n\t\t\tpass\r\n\t\telse:\r\n\t\t\tbreak\r\nt.Commit()<\/pre>\n<p>Enjoy !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you need to add new temperature in your project for at least 3 reasons : When you use SI units Revit default fluids are bugged. I have seen them bugged for more than 5 years&#8230; Templates were made in Fahrenheit and some temperatures just don&rsquo;t work when converted into \u00b0C or K. Revit default [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[80,38,34],"tags":[84,90,44,50,92],"class_list":["post-155","post","type-post","status-publish","format-standard","hentry","category-python","category-revit-en","category-script-en","tag-fluids","tag-fluidtype","tag-hydraulic","tag-revitpythonshell-en","tag-taskdialog"],"_links":{"self":[{"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts\/155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=155"}],"version-history":[{"count":3,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts\/155\/revisions"}],"predecessor-version":[{"id":158,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts\/155\/revisions\/158"}],"wp:attachment":[{"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}