I'm trying to learn modelling building energy systems through OS C# binding. Is there any complete tutorial to be used ? I've tried the following questions and answers but found them not complete :
- https://unmethours.com/question/19848/how-do-i-implement-open-studio-library-in-a-web-application/
- https://unmethours.com/question/19123/create-openstudio-model-object-from-an-osm-file/
- https://unmethours.com/question/17865/does-open-studio-have-api/
- https://unmethours.com/question/15093/link-openstudio-to-c-applications/
- https://unmethours.com/question/11404/how-to-use-the-openstudio-api/
- https://github.com/NREL/OpenStudio/tree/develop/doc
- https://unmethours.com/question/11881/csharp-for-openstudio/
- http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
- https://unmethours.com/question/9864/use-c-sqlfile-to-get-the-energy-plus-result/?answer=9877#post-id-9877
- https://unmethours.com/questions/12649/revisions/
A minimal example to run a simple model would be more than enough.
Edit after @macumber's answer :
Based on your suggestion, I've copied Alpha1 C# example to a different directory and also copy all dependent dll files into the corresponding folder and follow the instructions given here . Implementation executes without an error and produce a form to import .idf files. When I load the idf file here C:\Program Files\OpenStudio 1.12.0\Examples\resultsviewer\SmallOffice\SmallOffice.idf and say "Go", I got the following error message (similar error message are noted in this message also ):
Based on this, I've the following questions/issues :
- When the problem is resolved, will I be able to modify the simulation model (SmallOffice.idf) from C# ? Which methods should I use for this ?
- Inline with this error message, I wanted to test my OS installation with a different setting and used the implementation given here. However, this time I got the following exception
Then, I minimize the code in (3) to check what is wrong as in the following :
Path path = new Path("C:\Desktop\testModel.osm")
but still get the same error.
If the problem resolved, is the following code starting point to modify a model in C# ? If not, what should I do to load/create and execute a simple simulation model (.idf and or .osm files) from C# API ? Which methods should I use ?
Path path = new Path("C:\\Desktop\\testModel.osm");
OpenStudio.Model model = OpenStudio.Model.load(path).get();
Note that, the second line of the code was previously mentioned in this and this answers/questions.
Edit after @macumber's comments
- I've ensured that all dlls are copied and solution configuration set as x64 accordingly as in the following :
However, after that, I got the following error message :
Error CS0104 'Application' is an ambiguous reference between 'System.Windows.Forms.Application' and 'OpenStudio.Application' Alpha1 D:\OpenStudio\Alpha1\Alpha1\Program.cs 24 Active
so that I modified the code in Alpha1 as in the following :
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.Run(new MainForm());
now, the form successfully created but I got an exception when I want to load an IDF file (clicking the pointed button in the following picture)
Here is the exception and highlighted code segment in MainForm.cs that cause the exception
What I observed is, I was able to successfully clicking that button and pointing an IDF file when I run the implementation with x86 settings however I was getting .dll exceptions (as described above) but now, I changed to x64 settings and it results exceptions about form. Any idea to handle this issue ?
Edit after @macumber's last comments
Finally the Application form works and load the idf file as shown in the following picture. The problem is resolved by uncomment the [STAThread] line in Alpha1 application following this comment
. So I recommend everyone to uncomment [STAThread] line in Alpha1 application.
However, when I want to run the following code -to load
The rest of the question about loading and modifying an .osm file is moved to this question since this post is getting massive as described above-
Path path = new Path("C:\\Desktop\\testModel.osm");
OpenStudio.Model model = OpenStudio.Model.load(path).get();
I'm getting the following exception :
So, back to my previous question, how can I load an .osm file and modify it through C# binding ? Thanks in advance for helps. @macumber pointed out.