ladybug-tools / honeybee-legacy

:bee: Honeybee is a free and open source plugin to connect Grasshopper3D to EnergyPlus, Radiance, Daysim and OpenStudio for building energy and daylighting simulation
http://ladybug.tools
Other
124 stars 145 forks source link

PINVOKE Error With Most Recent ExportToOpenStudio #214

Closed chriswmackey closed 3 years ago

chriswmackey commented 9 years ago

@chiensiTB , Do you know why I get this error with the OpenStudio Component that you just committed?

image

mostaphaRoudsari commented 9 years ago

Ah! Did you recently updated your OpenStudio library files? I have to revert back to version 1.4. Give me a second and I will update the download link.

chriswmackey commented 9 years ago

Ok, Cool.

mostaphaRoudsari commented 9 years ago

Let's see if this will solve the issue: https://app.box.com/s/y2sx16k98g1lfd3r47zi

chriswmackey commented 9 years ago

I am still getting the error. Could we try another version?

mostaphaRoudsari commented 9 years ago

Did you try to unblock .dll files? I can upload version 1.4.0 tomorrow. We really need OpenStudio team's help for this. There is almost nothing that I can do about it. Have you ever successfully loaded the libraries? and do you remember what was the version. FYI: @axelstudios, @macumber

macumber commented 9 years ago

Hey @mostaphaRoudsari can you point me to some instructions on how to set up the Honeybee environment with OpenStudio? I had tried this at one point but have completely forgotten

chriswmackey commented 9 years ago

I am pretty sure that the files are unblocked. I was able to run the OpenStudio component before if that is any indication. How do I unblock the files in case that is the issue?

mostaphaRoudsari commented 9 years ago

Hi @macumber! Thank you for the very quick reply. We don't have an instruction but I can send you an example file tomorrow or even tonight and show you how to run it on your system. Let me know when do you want me to do it.

@chriswmackey if it doesn't show up when you right click and check the properties then it is unblocked.

chriswmackey commented 9 years ago

Ok. It is unblocked, then.

macumber commented 9 years ago

@mostaphaRoudsari I think some written instructions would be best, especially as I am sure something else is bound to come up in the future :-/

mostaphaRoudsari commented 9 years ago

@macumber you are definitely right.

Ok. Here is an example file: https://www.dropbox.com/s/pwpsravhwk0vlal/OpenStudioExample.gh?dl=0

Let me try right now to come up with an instruction:

  1. You need to get Rhino, Grasshopper, GHPython, and Honeybee and Ladybug installed on your system. If you haven't @chriswmackey already captured a video that shows how to get Honeybee and Ladybug installed on your system: https://www.youtube.com/watch?v=8UFkJL-aZy8&index=1&list=PLruLh1AdY-Sj_XGz3kzHUoWmpWDXNep1O
  2. Run Rhino and then in command line in Rhino type Grasshopper. It should open Grasshopper. I believe this is also in the video.
  3. Before opening the file you need to copy OpenStudio C# libraries (64 bit) to c:\ladybug\OpenStudio. I assume you already have a copy of the libraries ;)
  4. Now we are all ready to open the file. Go to File > Open in Grasshopper to open the example file. You can also just press Ctrl + O.
  5. When you open the file it should all be ready for you to run. You just need to double click on the Boolean in red (image below) and it will write osm file and run the simulation. openstudioexample
  6. Hopefully you will get an error similar to what Chris is getting which happens in the line that we import OpenStudio libraries. To see the code you can double click on the component.

Let me know if you have any question about any of the steps. Thanks!

macumber commented 9 years ago

I just wrote this for debugging this type of problem for the SketchUp plug-in, it might apply here. I'm going to try to get the Honeybee environment set up and try these steps but you guys might be able to beat me to it.

If none of the steps above work and you are on Windows, it is likely that there is a dynamic library being loaded from another application that is interfering with OpenStudio. If you just want to fix your problem, try copying the files libeay32.dll and ssleay32.dll from C:\Program Files (x86)\OpenStudio X.X.X\bin to C:\Program Files (x86)\SketchUp\SketchUp 2014, this will fix the problem 80% of the time.

If you want to investigate in more depth, download Dependency Walker. Extract the files and launch depends.exe. Navigate to File->Open and then browse to choose the SketchUp.exe under C:\Program Files (x86)\SketchUp\SketchUp 2014. This will examine all of the libraries loaded by SketchUp but not the libraries loaded by OpenStudio. Navigate to Profile->Start Profiling then press Ok in the dialog that pops up. This will launch SketchUp and attempt to load OpenStudio. Scroll down in the list of loaded libraries and look for the OpenStudio dlls. Expand the paths under the OpenStudio dlls and look for libraries that are being loaded from other locations. Often, some other program will install a different version of one of the libraries (usually libeay32.dll or ssleay32.dll) that OpenStudio uses. This other library will be in the path ahead of OpenStudio and will be loaded instead, this results in a hard crash of SketchUp. Correcting your path or copying the dlls from the OpenStudio bin directory into the SketchUp install directory will cause the correct dlls to be loaded when SketchUp starts.

macumber commented 9 years ago

Are you copying files from C:\Program Files\OpenStudio 1.5.0\CSharp\openstudio or from here C:\Program Files\OpenStudio 1.5.0\bin? I believe you may need both sets of dlls.

macumber commented 9 years ago

@mostaphaRoudsari I clicked on the red button but nothing seemed to happen. I read some of the readMe outputs but I didn't understand the messages (something about Type Error: Value cannot be null)

11-3-2014 11-14-00 pm

How do I get Honeybee to update itself? Does it automatically do that?

mostaphaRoudsari commented 9 years ago

@macumber we only copy the ones from C:\Program Files\OpenStudio 1.5.0\CSharp\openstudio

If you zoom in on the orange component there will be a baloon on top of the component that you can click on it and read the message. Here is an example:

image

Is the path to weather file correct?

You can update Honeybee from github but you shouldn't need to do that right now.

mostaphaRoudsari commented 9 years ago

@macumber just as a reminder we are using 64bit bindings of C#.

mostaphaRoudsari commented 9 years ago

@macumber I followed your instruction and copied .dlls from both folders to c:\ladybug\OpenStudio but it still gives me the same error

@chriswmackey I also updated the files here if you want to give it a try on your system: https://app.box.com/s/y2sx16k98g1lfd3r47zi

I'm also adding @jacoposartore to the discussion as he has the same issue on his system (https://github.com/mostaphaRoudsari/Honeybee/issues/170)

macumber commented 9 years ago

@mostaphaRoudsari can you try following the steps to use dependency walker to diagnose if any dlls are getting loaded incorrectly? you might also try making sure that C:\ladybug\OpenStudio is the first entry in your path.

mostaphaRoudsari commented 9 years ago

@macumber will test it later this week and update you. Can you re-produce the error on your system?

macumber commented 9 years ago

@mostaphaRoudsari No but I can't reproduce the successful run either

mostaphaRoudsari commented 9 years ago

@macumber I finally get a chance to check this. I'm not sure if I can follow your the steps that you mentioned in Grasshopper. There is no Grasshopper.exe file that I can use for profiling.

BTW here is the results when I load OpenStudio.dll

image

I tried to copy IESHIMS.dll into the folder but then it gives me another error.

The most strange part is that now I can import openstudio with no problem on my system. Makes it really hard to debug. The path is at the end of system paths.

@chriswmackey can you try similar approach on your system? Here is a simple file that tries to import the libraries:https://www.dropbox.com/s/p6ze63n3k3ctmqt/testImportingOpenStudioLibs.gh?dl=0

Here is OpenStudio libraries that I use: https://www.dropbox.com/s/4azxa9shit0wpn2/openstudio_CSharp_64bits_Ver.1.5.0.zip?dl=0 Copy them to c:\ladybug\openstudio

@macumber you should also be able to run the grasshopper file too. It is a component that only tries to import the library and print it.

chriswmackey commented 9 years ago

Hello @macumber and @mostaphaRoudsari ,

I'm sorry for getting back so late here and for not trying the previous suggestion (a month ago) on my system. I first tried opening the GH file that you posted, Mostapha, and got and, as expected, got an error: initial attempt

Next, I tried copying the libraries into C:\Ladybug\openstudio and re-opened the GH file but I still got the same error. Then, I realized that the script that you wrote, Mostapha, was importing the libraries from the Honeybee default folder and so I copied the libraries to C:\Users\cwmackey\AppData\Roaming\Ladybug\OpenStudio. I still got the same error.

Let me know if there is anything else that you would like me to test. -Chris

chriswmackey commented 9 years ago

@macumber and @mostaphaRoudsari ,

Scratch my last comment. I looks like the libraries are importing well on my system but there was just something going wrong with the Grasshopper display. As you can see from the screenshot below, the libraries seems to be coming in well: import working ok

chriswmackey commented 9 years ago

To be clear, I still get the same PINVOKE error when I try to run the OpenStudio component: image

mostaphaRoudsari commented 9 years ago

@chriswmackey thanks for testing. Now that I tested OpenStudio component again it also fails on my system. The error is not in import line but when the code initializes the model.

ops.Model()

image

@macumber can you please test this file: https://www.dropbox.com/s/p6ze63n3k3ctmqt/testImportingOpenStudioLibs.gh?dl=0

It is a pretty simple code and should run on your system without giving the warnings.

import scriptcontext as sc
import os

if sc.sticky.has_key('honeybee_release'):

    openStudioLibFolder = os.path.join(sc.sticky["Honeybee_DefaultFolder"], "OpenStudio")

    if os.path.isdir(openStudioLibFolder) and os.path.isfile(os.path.join(openStudioLibFolder, "openStudio.dll")):

        import clr
        clr.AddReferenceToFileAndPath(openStudioLibFolder+"\\openStudio.dll")

        import sys
        if openStudioLibFolder not in sys.path:
            sys.path.append(openStudioLibFolder)

        import OpenStudio as ops

        ops.Model()
    else:
        print "Can't find OpenStudio library in " + openStudioLibFolder
macumber commented 9 years ago

@mostaphaRoudsari @chiensiTB I tried looking into this today. I downloaded the newest version of Ladybug/Honeybee from food4rhino, removed my old Ladybug/Honeybee, and updated to the new versions. I removed my old C:\ladybug\OpenStudio, added a new C:\Users\dmacumbe\AppData\Roaming\Ladybug\OpenStudio, and copied the linked OpenStudio dlls over there. When I try to run the testImportingOpenStudioLibs.gh script I get this output:

Runtime error (IOException): file does not exist: C:\Users\dmacumbe\AppData\Roaming\Ladybug\OpenStudio\openStudio.dll Traceback: line 12, in script

I corrected the case of OpenStudio.dll but still get the same error. The file does exist on my computer. I suspect some other problem is happening, see this post http://ironpython.codeplex.com/workitem/31749.

Is this the latest error you guys are seeing?

mostaphaRoudsari commented 9 years ago

@macumber thank you for looking into this. No we don't have the issue of finding the file. Did you unblock your .dlls? (Right click on the file > unblock?)

try this sample file. It only tries to import the library. Thanks again and let me know if you want to set up a googleHangout and try to figure it out together. This will be a huge help to us to go forward.

macumber commented 9 years ago

Hey Mostapha, I had problems with the OpenStudio package that OpenStudioExample.gh pointed me to, https://app.box.com/s/y2sx16k98g1lfd3r47zi.

Instead, I downloaded the 1.6.0 64bit OpenStudio installer from https://www.openstudio.net/downloads, ran the installer, then copied all the files from 'C:\Program Files\OpenStudio 1.6.0\CSharp\openstudio' to 'C:\Users\dmacumbe\AppData\Roaming\Ladybug\OpenStudio'.

After that testImportingOpenStudioLibs.gh works fine, and OpenStudioExample.gh works but I get this message (I don't know how to change units):

Currently the OpenStudio component only works in meters. Change the units to Meters and try again!

If you guys use the OpenStudio dlls from our installer do you still run into pInvoke problems?

macumber commented 9 years ago

Ok, figured out how to change units and ran the simulation :-)

However, OS 1.6.0 writes a E+ 8.2 file but Ladybug used E+ 8.1 so this was not exactly perfect....

@chiensiTB @mostaphaRoudsari

mostaphaRoudsari commented 9 years ago

@macumber you imported the latest version of OpenStudio with no problem! That's great. Can you share the libraries with us so we can also try it on our systems?

The most recent version of Honeybee on github actually works with both 8.1 and 8.2

macumber commented 9 years ago

@mostaphaRoudsari like I said, just download the installer from https://www.openstudio.net/downloads, run the installer, then copy all the files from 'C:\Program Files\OpenStudio 1.6.0\CSharp\openstudio' to 'C:\Users#{your_user}\AppData\Roaming\Ladybug\OpenStudio'.

mostaphaRoudsari commented 9 years ago

@macumber as far as I can see the site is under maintenance

image

but I have also a question. Are you shipping 64bits library also with installation? I remember it used to be 32bits which wasn't working for us.

macumber commented 9 years ago

Weird, the website was working for me. You can also get downloads on our github page, here is a link to the 1.6.0 release, https://github.com/NREL/OpenStudio/releases/tag/v1.6.0

Direct link to 64 bit installer, https://github.com/NREL/OpenStudio/releases/download/v1.6.0/OpenStudio-1.6.0.1229eac298-Win64.exe

Our default installer on Windows is now 64 bit since SketchUp 2015 is now 64 bit

mostaphaRoudsari commented 9 years ago

@macumber Thanks. Downloading right now! I'll let you know if it works on my system.

@chiensiTB, @chriswmackey and @jacoposartore can you guys also test on your systems and let us know the results?

mostaphaRoudsari commented 9 years ago

@macumber :( - Still the same error on my system.

image

macumber commented 9 years ago

Hmm, bummer. I am uploading a copy of my debug build dlls to this link (will take some time to upload), https://www.dropbox.com/s/oczwi4yylxixcvg/OpenStudio_1_6_3.zip?dl=0

Maybe those will give you some more information. If not, I think the thing to do would be to have you build your own 64 bit OpenStudio bindings and try those out, that will give you better debug information.

The only other idea I have is instead of appending the OpenStudio dir to the end of your path, you might try adding at the front of the path.

macumber commented 9 years ago

Ok this is definitely a path issue, I was just able to reproduce by doing this at the command line:

C:\Program Files\Rhinoceros 5 (64-bit)\System>set PATH="" C:\Program Files\Rhinoceros 5 (64-bit)\System>Rhino.exe

mostaphaRoudsari commented 9 years ago

Are you talking about sys.path or are you talking about my windows system path? I added the path as the first item to sys.path and it is still the same

image

macumber commented 9 years ago

Have you tried adding this line (works for me when starting with an empty path):

os.environ['PATH'] = os.environ['PATH'] + ";" + openStudioLibFolder

Looks like sys.path is just the Python path, does not actually affect the system path which is where dependent libraries are loaded from

mostaphaRoudsari commented 9 years ago

Just tried and it doesn't help. the same error. There should be something else in your Windows path that I don't have in mine. I hope the debug version tells us something about that...

jacoposartore commented 9 years ago

hi @mostaphaRoudsari I just have tried on my system what @macumber did (copying the dlls within C:\Program Files\OpenStudio 1.6.0\CSharp\openstudio into c:\ladybug\openstudio) and now both the testImportingOpenStudioLibs.gh and the OpenStudioExample.gh are working fine.

testimportingopenstudiolibs

In particular, as regards the last file, the Export to OpenStudio component returns an orange error about not having the latest OpenStudio libraries but the .osm file is eventually generated as you can see from the screenshot.

openstudioexample

openstudioopenexample

I have added a screenshot form Google Sketchup, the file is perfectly generated. Great job guys!

macumber commented 9 years ago

Hmm @mostaphaRoudsari, in my testing I reproduced your error by completely wiping out my PATH environment variable before starting Rhino. Then I fixed the error by adding the openStudioLibFolder to the PATH environment variable (Rhino did add some Rhino paths to this variable when it started) in the script before loading the assembly file, here is the code that did that:

os.environ['PATH'] = os.environ['PATH'] + ";" + openStudioLibFolder

I guess that you could test by adding openStudioLibFolder to your regular windows PATH, but I think my fix will be better for most of your users as they won't have to modify their PATH permanently. Could you try again to see if this works for you?

mostaphaRoudsari commented 9 years ago

@macumber I tested on my work machine and it works fine. Still have the issue on my laptop. Also used the new debug libraries and it generates similar error report. Nothing really helpful.

image

Thanks @jacoposartore

macumber commented 9 years ago

Thanks everyone for testing, @mostaphaRoudsari I missed some DLLs in my first zip of debug libraries, can you re-download this one and try again on your laptop?

https://www.dropbox.com/s/oczwi4yylxixcvg/OpenStudio_1_6_3.zip?dl=0

Also, it is possible there is something in your path that is causing an issue (alternate versions of Qt or OpenSSL would be my guess). Can you open a command prompt in your Rhino folder and type these commands:

C:\Program Files\Rhinoceros 5 (64-bit)\System>set PATH="" C:\Program Files\Rhinoceros 5 (64-bit)\System>set PYTHONPATH="" C:\Program Files\Rhinoceros 5 (64-bit)\System>Rhino.exe

That will launch Rhino from an empty environment, then when you run the code you will be starting from a clean start. It's ugly but in OpenStudio we get around these issues by always adding our stuff to the front of the path when our applications load.

mostaphaRoudsari commented 9 years ago

:|. I cleaned it up inside the code and also tried your solution and in both cases it doesn't work. as you can see I only have c:\openstudio\openstudio in both Windows path and python's sys.path

image

mostaphaRoudsari commented 9 years ago

@macumber I'm uninstalling OpenSSL and Qt! Let's see if that helps.

macumber commented 9 years ago

Can you try this code:

import scriptcontext as sc
import os

if sc.sticky.has_key('honeybee_release'):

    openStudioLibFolder = os.path.join(sc.sticky["Honeybee_DefaultFolder"], "OpenStudio")

    if os.path.isdir(openStudioLibFolder) and os.path.isfile(os.path.join(openStudioLibFolder, "OpenStudio.dll")):

        print os.environ['PATH']
        os.environ['PATH'] = openStudioLibFolder + ";" + os.environ['PATH']
        print os.environ['PATH']

        import sys

        if openStudioLibFolder not in sys.path:
            sys.path.append(openStudioLibFolder)

        import clr
        clr.AddReferenceToFileAndPath(openStudioLibFolder+"\\OpenStudio.dll")

        import OpenStudio as ops

        print ops.Model()
    else:
        print "Can't find OpenStudio library in " + openStudioLibFolder
mostaphaRoudsari commented 9 years ago

No luck! I also removed Qt and uninstalled OpenSSL

image

macumber commented 9 years ago

I see a bunch of other stuff in your path, are you using the command prompt to clear PATH and PYTHON path (will only affect that command prompt session) and start Rhino from a clean environment?

mostaphaRoudsari commented 9 years ago

I copied my second try. Here is the first one with clean path:

image