{"id":149,"date":"2015-11-01T18:16:22","date_gmt":"2015-11-01T17:14:28","guid":{"rendered":"http:\/\/pythoncvc.net\/?p=149"},"modified":"2015-11-01T18:14:28","modified_gmt":"2015-11-01T17:14:28","slug":"working-with-fluid-properties-22-using-coolprop-in-ironpython","status":"publish","type":"post","link":"https:\/\/pythoncvc.net\/?p=149","title":{"rendered":"Working with fluid properties 2\/2 : Using CoolProp in IronPython"},"content":{"rendered":"<p>Unfortunately, python wrapper cannot be used in ironpython environment (or at least I didn&rsquo;t success to do so). So I had to find another way to use it directly in Revit. I used <a href=\"http:\/\/www.coolprop.org\/coolprop\/wrappers\/SharedLibrary\/index.html#shared-library\" target=\"_blank\">shared library (.dll)<\/a> which can be downloaded on sourceforge : <a href=\"http:\/\/sourceforge.net\/projects\/coolprop\/files\/CoolProp\/5.1.1\/shared_library\/Windows\/64bit\/\" target=\"_blank\">http:\/\/sourceforge.net\/projects\/coolprop\/files\/CoolProp\/5.1.1\/shared_library\/Windows\/64bit\/<\/a>.<\/p>\n<p>It was a little tricky for a non professional programmer like me to understand how to call this CoolProp.dll properly. <a href=\"https:\/\/docs.python.org\/2\/library\/ctypes.html\" target=\"_blank\">ctypes tutorial<\/a> describe how to do it with standard python library. CoolProp documentation says that CoolProp support stdcall and cdecl call which means that you are supposed to be able to use cdll and windll. I tried and failed with windll then I found <a href=\"http:\/\/stackoverflow.com\/questions\/28644287\/calling-c-64bit-shared-library-from-python\" target=\"_blank\">a post on stackoverflow<\/a> that describe the same process i used but with cdll. I still don&rsquo;t understand why windll didn&rsquo;t work but at least I can use CoolProp in an IronPython environment.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">import ctypes\r\n\r\n#Load CoolProp shared library\r\nCP = ctypes.cdll.LoadLibrary(\"\/PathTo\/CoolProp.dll\")\r\n#making PropsSI function call shorter\r\nPropsSI = CP.PropsSI\r\n#Convert python data type entered in PropsSI function call to expected argtypes for PropsSI function in the .dll\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\n#Convert returned value from .dll to desired data type which is a float in python\r\nPropsSI.restype = ctypes.c_double\r\n\r\n#You can then call PropsSI function as in previous article\r\nprint PropsSI('C','T',275.15,'P',101325,'INCOMP::Water')<\/pre>\n<p>For more info about data types check <a href=\"https:\/\/docs.python.org\/2\/library\/ctypes.html#fundamental-data-types\" target=\"_blank\">here<\/a><\/p>\n<p>Next article will talk about how to add fluids in Revit using CoolProp power !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unfortunately, python wrapper cannot be used in ironpython environment (or at least I didn&rsquo;t success to do so). So I had to find another way to use it directly in Revit. I used shared library (.dll) which can be downloaded on sourceforge : http:\/\/sourceforge.net\/projects\/coolprop\/files\/CoolProp\/5.1.1\/shared_library\/Windows\/64bit\/. It was a little tricky for a non professional programmer like [&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],"tags":[84,44,86],"class_list":["post-149","post","type-post","status-publish","format-standard","hentry","category-python","tag-fluids","tag-hydraulic","tag-ironpython"],"_links":{"self":[{"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts\/149","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=149"}],"version-history":[{"count":2,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts\/149\/revisions"}],"predecessor-version":[{"id":151,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=\/wp\/v2\/posts\/149\/revisions\/151"}],"wp:attachment":[{"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythoncvc.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}