Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 :

  1. https://unmethours.com/question/19848/how-do-i-implement-open-studio-library-in-a-web-application/
  2. https://unmethours.com/question/19123/create-openstudio-model-object-from-an-osm-file/
  3. https://unmethours.com/question/17865/does-open-studio-have-api/
  4. https://unmethours.com/question/15093/link-openstudio-to-c-applications/
  5. https://unmethours.com/question/11404/how-to-use-the-openstudio-api/
  6. https://github.com/NREL/OpenStudio/tree/develop/doc
  7. https://unmethours.com/question/11881/csharp-for-openstudio/
  8. http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
  9. https://unmethours.com/question/9864/use-c-sqlfile-to-get-the-energy-plus-result/?answer=9877#post-id-9877
  10. https://unmethours.com/questions/12649/revisions/

A minimal example to run a simple model would be more than enough.

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 :

  1. https://unmethours.com/question/19848/how-do-i-implement-open-studio-library-in-a-web-application/
  2. https://unmethours.com/question/19123/create-openstudio-model-object-from-an-osm-file/
  3. https://unmethours.com/question/17865/does-open-studio-have-api/
  4. https://unmethours.com/question/15093/link-openstudio-to-c-applications/
  5. https://unmethours.com/question/11404/how-to-use-the-openstudio-api/
  6. https://github.com/NREL/OpenStudio/tree/develop/doc
  7. https://unmethours.com/question/11881/csharp-for-openstudio/
  8. http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
  9. https://unmethours.com/question/9864/use-c-sqlfile-to-get-the-energy-plus-result/?answer=9877#post-id-9877
  10. 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 show 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 ):

image description

Based on this, I've the following questions/issues :

  1. 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 ?
  2. 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 image description
  3. 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.

  4. 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.

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 :

  1. https://unmethours.com/question/19848/how-do-i-implement-open-studio-library-in-a-web-application/
  2. https://unmethours.com/question/19123/create-openstudio-model-object-from-an-osm-file/
  3. https://unmethours.com/question/17865/does-open-studio-have-api/
  4. https://unmethours.com/question/15093/link-openstudio-to-c-applications/
  5. https://unmethours.com/question/11404/how-to-use-the-openstudio-api/
  6. https://github.com/NREL/OpenStudio/tree/develop/doc
  7. https://unmethours.com/question/11881/csharp-for-openstudio/
  8. http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
  9. https://unmethours.com/question/9864/use-c-sqlfile-to-get-the-energy-plus-result/?answer=9877#post-id-9877
  10. 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 show 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 ):

image description

Based on this, I've the following questions/issues :

  1. 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 ?
  2. 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 image description
  3. 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.

  4. 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.

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 :

  1. https://unmethours.com/question/19848/how-do-i-implement-open-studio-library-in-a-web-application/
  2. https://unmethours.com/question/19123/create-openstudio-model-object-from-an-osm-file/
  3. https://unmethours.com/question/17865/does-open-studio-have-api/
  4. https://unmethours.com/question/15093/link-openstudio-to-c-applications/
  5. https://unmethours.com/question/11404/how-to-use-the-openstudio-api/
  6. https://github.com/NREL/OpenStudio/tree/develop/doc
  7. https://unmethours.com/question/11881/csharp-for-openstudio/
  8. http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
  9. https://unmethours.com/question/9864/use-c-sqlfile-to-get-the-energy-plus-result/?answer=9877#post-id-9877
  10. 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 ):

image description

Based on this, I've the following questions/issues :

  1. 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 ?
  2. 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 image description
  3. 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.

  4. 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

  1. I've ensured that all dlls are copied and solution configuration set as x64 accordingly as in the following : image description 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)

image description

Here is the exception and highlighted code segment in MainForm.cs that cause the exception

image description

What I observed is, I was successfully click that button and point 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 ?

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 :

  1. https://unmethours.com/question/19848/how-do-i-implement-open-studio-library-in-a-web-application/
  2. https://unmethours.com/question/19123/create-openstudio-model-object-from-an-osm-file/
  3. https://unmethours.com/question/17865/does-open-studio-have-api/
  4. https://unmethours.com/question/15093/link-openstudio-to-c-applications/
  5. https://unmethours.com/question/11404/how-to-use-the-openstudio-api/
  6. https://github.com/NREL/OpenStudio/tree/develop/doc
  7. https://unmethours.com/question/11881/csharp-for-openstudio/
  8. http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
  9. https://unmethours.com/question/9864/use-c-sqlfile-to-get-the-energy-plus-result/?answer=9877#post-id-9877
  10. 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 ):

image description

Based on this, I've the following questions/issues :

  1. 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 ?
  2. 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 image description
  3. 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.

  4. 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

  1. I've ensured that all dlls are copied and solution configuration set as x64 accordingly as in the following : image description 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)

image description

Here is the exception and highlighted code segment in MainForm.cs that cause the exception

image description

What I observed is, I was able to successfully click clicking that button and point 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 ?

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 :

  1. https://unmethours.com/question/19848/how-do-i-implement-open-studio-library-in-a-web-application/
  2. https://unmethours.com/question/19123/create-openstudio-model-object-from-an-osm-file/
  3. https://unmethours.com/question/17865/does-open-studio-have-api/
  4. https://unmethours.com/question/15093/link-openstudio-to-c-applications/
  5. https://unmethours.com/question/11404/how-to-use-the-openstudio-api/
  6. https://github.com/NREL/OpenStudio/tree/develop/doc
  7. https://unmethours.com/question/11881/csharp-for-openstudio/
  8. http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
  9. https://unmethours.com/question/9864/use-c-sqlfile-to-get-the-energy-plus-result/?answer=9877#post-id-9877
  10. 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 ):

image description

Based on this, I've the following questions/issues :

  1. 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 ?
  2. 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 image description
  3. 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.

  4. 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

  1. I've ensured that all dlls are copied and solution configuration set as x64 accordingly as in the following : image description 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)

image description

Here is the exception and highlighted code segment in MainForm.cs that cause the exception

image description

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 image description. So I recommend everyone to

However, when I want to run the following code -to load an .osm file 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 : image description

So, back to my previous question, how can I load an .osm file and modify it through C# binding ? Thanks in advance for helps.

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 :

  1. https://unmethours.com/question/19848/how-do-i-implement-open-studio-library-in-a-web-application/
  2. https://unmethours.com/question/19123/create-openstudio-model-object-from-an-osm-file/
  3. https://unmethours.com/question/17865/does-open-studio-have-api/
  4. https://unmethours.com/question/15093/link-openstudio-to-c-applications/
  5. https://unmethours.com/question/11404/how-to-use-the-openstudio-api/
  6. https://github.com/NREL/OpenStudio/tree/develop/doc
  7. https://unmethours.com/question/11881/csharp-for-openstudio/
  8. http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
  9. https://unmethours.com/question/9864/use-c-sqlfile-to-get-the-energy-plus-result/?answer=9877#post-id-9877
  10. 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 ):

image description

Based on this, I've the following questions/issues :

  1. 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 ?
  2. 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 image description
  3. 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.

  4. 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

  1. I've ensured that all dlls are copied and solution configuration set as x64 accordingly as in the following : image description 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)

image description

Here is the exception and highlighted code segment in MainForm.cs that cause the exception

image description

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 image description. So I recommend everyone to uncomment [STAThread] line in Alpha1 application.

However, when I want to run the following code -to load an .osm file 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 : image description

So, back to my previous question, how can I load an .osm file and modify it through C# binding ? Thanks in advance for helps.

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 :

  1. https://unmethours.com/question/19848/how-do-i-implement-open-studio-library-in-a-web-application/
  2. https://unmethours.com/question/19123/create-openstudio-model-object-from-an-osm-file/
  3. https://unmethours.com/question/17865/does-open-studio-have-api/
  4. https://unmethours.com/question/15093/link-openstudio-to-c-applications/
  5. https://unmethours.com/question/11404/how-to-use-the-openstudio-api/
  6. https://github.com/NREL/OpenStudio/tree/develop/doc
  7. https://unmethours.com/question/11881/csharp-for-openstudio/
  8. http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/
  9. https://unmethours.com/question/9864/use-c-sqlfile-to-get-the-energy-plus-result/?answer=9877#post-id-9877
  10. 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 ):

image description

Based on this, I've the following questions/issues :

  1. 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 ?
  2. 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 image description
  3. 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.

  4. 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

  1. I've ensured that all dlls are copied and solution configuration set as x64 accordingly as in the following : image description 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)

image description

Here is the exception and highlighted code segment in MainForm.cs that cause the exception

image description

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 image description. 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 : image description

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.