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

Loading and editing an .osm file in OS C# binding

Hi everyone,

This question is continuation of my previous post. In that question, I resolved the issue of running Alpha1 test C# implementation with @macumber's helps. As he suggested and since the previous post getting massive, I'm posting the new question here.

I'm trying to load and modify an .osm file via OpenStudio C# binding using Visual Studio 2015. I've a "testModel.osm" file that is working via OpenStudio GUI without any problem. I'm using the following code segment to load it in C#.

Path path = new Path("C:\\Desktop\\testModel.osm");
OpenStudio.Model model = OpenStudio.Model.load(path).get();

and having the following exception image description O also changed the second line with the following two lines but still having the same exception

OpenStudio.VersionTranslator translator = new OpenStudio.VersionTranslator();
OpenStudio.Model model = translator.loadModel(path).get();

Note that execution of the following line alone is perfectly fine.

Path path = new Path("C:\\Desktop\\testModel.osm");

Thanks for your helps in advance.

Loading and editing an .osm file in OS C# binding

Hi everyone,

This question is continuation of my previous post. In that question, I resolved the issue of running Alpha1 test C# implementation with @macumber's helps. As he suggested and since the previous post getting massive, I'm posting the new question here.

I'm trying to load and modify an .osm file via OpenStudio C# binding using Visual Studio 2015. I've a "testModel.osm" file that is working via OpenStudio GUI without any problem. I'm using the following code segment to load it in C#.

Path path = new Path("C:\\Desktop\\testModel.osm");
OpenStudio.Model model = OpenStudio.Model.load(path).get();

and having the following exception image description O also changed the second line with the following two lines but still having the same exception

OpenStudio.VersionTranslator translator = new OpenStudio.VersionTranslator();
OpenStudio.Model model = translator.loadModel(path).get();

Note that execution of the following line alone is perfectly fine.

Path path = new Path("C:\\Desktop\\testModel.osm");

Thanks for your helps in advance.

Edit after @macumber's comment:

Thanks @macumber, I modify the implementation as in the following :

Path path = new Path("C:\\Desktop\\testModel.osm");
OpenStudio.VersionTranslator translator = new OpenStudio.VersionTranslator();
OpenStudio.OptionalModel optionalModel = translator.loadModel(path);
foreach(var i in translator.errors())
   {
       Console.WriteLine(i.logMessage());
   }
foreach(var i in translator.warnings())
   {
        Console.WriteLine(i.logMessage());
   }
if (optionalModel.is_initialized())
   {
        OpenStudio.Model model = optionalModel.get();
        Console.WriteLine("optional model is initialised");
   }
else
    {
        Console.WriteLine("optional model is not initialized");
    }

And here is the console output after executing the program :

image description

Unfortunately, I couldn't get any error or warning message printed. How can we proceed ?

Loading and editing an .osm file in OS C# binding

Hi everyone,

This question is continuation of my previous post. In that question, I resolved the issue of running Alpha1 test C# implementation with @macumber's helps. As he suggested and since the previous post getting massive, I'm posting the new question here.

I'm trying to load and modify an .osm file via OpenStudio C# binding using Visual Studio 2015. I've a "testModel.osm" file that is working via OpenStudio GUI without any problem. I'm using the following code segment to load it in C#.

Path path = new Path("C:\\Desktop\\testModel.osm");
OpenStudio.Model model = OpenStudio.Model.load(path).get();

and having the following exception image description O also changed the second line with the following two lines but still having the same exception

OpenStudio.VersionTranslator translator = new OpenStudio.VersionTranslator();
OpenStudio.Model model = translator.loadModel(path).get();

Note that execution of the following line alone is perfectly fine.

Path path = new Path("C:\\Desktop\\testModel.osm");

Thanks for your helps in advance.

Edit after @macumber's comment:

Thanks @macumber, I modify the implementation as in the following :

Path path = new Path("C:\\Desktop\\testModel.osm");
OpenStudio.VersionTranslator translator = new OpenStudio.VersionTranslator();
OpenStudio.OptionalModel optionalModel = translator.loadModel(path);
foreach(var i in translator.errors())
   {
       Console.WriteLine(i.logMessage());
   }
foreach(var i in translator.warnings())
   {
        Console.WriteLine(i.logMessage());
   }
if (optionalModel.is_initialized())
   {
        OpenStudio.Model model = optionalModel.get();
        Console.WriteLine("optional model is initialised");
   }
else
    {
        Console.WriteLine("optional model is not initialized");
    }

And here is the console output after executing the program :

image description

Unfortunately, I couldn't get any error or warning message printed. How can we proceed ?

Loading and editing an .osm file in OS C# binding

Hi everyone,

This question is continuation of my previous post. In that question, I resolved the issue of running Alpha1 test C# implementation with @macumber's helps. As he suggested and since the previous post getting massive, I'm posting the new question here.

I'm trying to load and modify an .osm file via OpenStudio C# binding using Visual Studio 2015. I've a "testModel.osm" file that is working via OpenStudio GUI without any problem. I'm using the following code segment to load it in C#.

Path path = new Path("C:\\Desktop\\testModel.osm");
OpenStudio.Model model = OpenStudio.Model.load(path).get();

and having the following exception image description O also changed the second line with the following two lines but still having the same exception

OpenStudio.VersionTranslator translator = new OpenStudio.VersionTranslator();
OpenStudio.Model model = translator.loadModel(path).get();

Note that execution of the following line alone is perfectly fine.

Path path = new Path("C:\\Desktop\\testModel.osm");

Thanks for your helps in advance.

Edit after @macumber's comment:

Thanks @macumber, I modify the implementation as in the following :

Path path = new Path("C:\\Desktop\\testModel.osm");
OpenStudio.VersionTranslator translator = new OpenStudio.VersionTranslator();
OpenStudio.OptionalModel optionalModel = translator.loadModel(path);
foreach(var i in translator.errors())
   {
       Console.WriteLine(i.logMessage());
   }
foreach(var i in translator.warnings())
   {
        Console.WriteLine(i.logMessage());
   }
if (optionalModel.is_initialized())
   {
        OpenStudio.Model model = optionalModel.get();
        Console.WriteLine("optional model is initialised");
   }
else
    {
        Console.WriteLine("optional model is not initialized");
    }

And here is the console output after executing the program :

image description

Unfortunately, I couldn't get any error or warning message printed. How can we proceed ?