How to get start modeling with OS C# Binding
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...
- https://unmethours.com/question/19123...
- https://unmethours.com/question/17865...
- https://unmethours.com/question/15093...
- https://unmethours.com/question/11404...
- https://github.com/NREL/OpenStudio/tr...
- https://unmethours.com/question/11881...
- http://nrel.github.io/OpenStudio-user...
- https://unmethours.com/question/9864/...
- https://unmethours.com/questions/1264...
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 ...
@cemal are you just interested in running workflows with measures, or do you wan to directly interact with the OpenStudio API? Might have different answers based on this.
@David Goldwasser I need to directly interact with the OpenStudio API. Thanks in advance.
The program launches fine but crashes as soon as it tries to load OpenStudio.dll and its dependencies. Here are some tips:
Doing this worked for me. We can answer your questions about what to do next after you can run the initial program.
I have not seen that dialog error, I am using Visual Studio 2013, it seems like you are using 2015. I would try setting your program to single threaded like the dialog says, Googling the error message should provide help. It seems like you are getting closer.
Thanks @macumber, I successfully load an idf file. However, still having issues to load and modify an osm file as explained in the modified question.