2

OpenStudio SDK - using GbXML reverse Translator

I have managed to make an optional model by using the gbxml reverse translator using the code below:

require 'openstudio'

translator = OpenStudio::GbXML::GbXMLReverseTranslator.new

newModel = translator.loadModel(OpenStudio::Path.new('C:\Users\szilasia\Documents\dscEngine\gbxml3.xml'))

Unfortunately the model is not initalized so I can't convert it to a model as seen here

How can I initalize the model?

antonszilasi's avatar
1.5k
antonszilasi
asked 2017-09-26 21:50:58 -0500
__AmirRoth__'s avatar
4.4k
__AmirRoth__
updated 2017-09-27 19:19:12 -0500
edit flag offensive 0 remove flag close merge delete

Comments

@antonszilasi feel free to update the question with your answer from Slack.

MatthewSteen's avatar MatthewSteen (2017-09-28 14:50:31 -0500) edit
add a comment see more comments

1 Answer

3

You'll have to check if the optional model is initialized and then cast to a Model object with .get, as shown in this answer.

ericringold's avatar
10.6k
ericringold
answered 2017-09-27 10:53:37 -0500
edit flag offensive 0 remove flag delete link

Comments

@Eric Ringold thank you for your answer! Unfortunately the model is not initalized how can I initalize it?

antonszilasi's avatar antonszilasi (2017-09-27 12:44:54 -0500) edit
1

From Dan's answer:

if (optionalModel.is_initialized()){
  OpenStudio.Model model = optionalModel.get(); // call get only if it is initialized
}

If is_initialized returns false, there is something going wrong in the translation. You could try to print the translator errors and warnings (again, see Dan's answer).

ericringold's avatar ericringold (2017-09-27 12:46:57 -0500) edit
add a comment see more comments